public static void CopyPackFiles() { var SB = new StringBuilder(); bool Exists = Directory.Exists(@"C:\GamePack"); try { if (!Exists) { Directory.CreateDirectory(str2 + folder); foreach (var file in new DirectoryInfo(GetPath()).GetFiles("*.d3d", SearchOption.TopDirectoryOnly)) { file.CopyTo(Path.Combine(str2, file.Name)); } foreach (var file2 in new DirectoryInfo(GetPath() + folder).GetFiles("*.ini", SearchOption.TopDirectoryOnly)) { file2.CopyTo(Path.Combine(str2 + folder, file2.Name)); } } } catch (IOException e) { SB.AppendLine(e.ToString()); } catch (SecurityException e) { SB.AppendLine(e.ToString()); } catch (Exception e) { SB.AppendLine(e.ToString()); } File.WriteAllText("Error.log", SB.ToString()); } How to copy files to 1 part of a folder, and 2 part to an internal folder using Linq?
Is it possible to do without a secondary cycle (where the files are copied into the internal folder) ?!
Should I use Task in this example?
Path.Combine. Instead ofnew DirectoryInfo(GetPath() + folder).GetFilesyou can useDirectory.GetFiles. LINQ is not particularly needed here, maximum - you can glue the result of two calls toGetFilesthroughConcat, and drive one cycle according to the result :) - PashaPash ♦Path.Combineinside the loop) I’m wondering how to foldConcatwithConcatin 1 loop, kindly give me some example code, I just didn’t see how they do it when copying or the like. - GooliveRstr2 + folder. I would post an example, but with LINQ it turns out to be scary and less readable. LINQ is used to build queries. And you do not need a request here, two cycles (or a method) are simpler and more readable. Neither LINQ nor Task is needed here. - PashaPash ♦+we put Path.Combine :) Thank you, but it's still interesting to see Concat in one cycle - GooliveR