public static void Main() { DS_Form newForm = new DS_Form(); string SourcePath = newForm.DS_OpenFolderDialogForm("", "Chose source folder:").ToString(); string BasedirName = new DirectoryInfo(SourcePath).Name; string TopFolderPath = SourcePath.Replace(BasedirName, ""); string TextFilePath = newForm.DS_OpenFileDialogForm("Chose the txt file with list of names:").ToString(); string[] lines = File.ReadAllLines(TextFilePath); //Copying and renaming directories try { foreach (string line in lines) { if (line != BasedirName) { string DestinationPath = TopFolderPath + line; DirCopy(SourcePath, DestinationPath); DirRename(DestinationPath, line, BasedirName); } } } catch (Exception ex) { Console.WriteLine("An error occured: " + ex.Message); } Console.WriteLine("Done!"); Console.ReadLine(); }
public static void Main1() { DS_Form newForm = new DS_Form(); string SourceFilePath = newForm.DS_OpenFileDialogForm("Chose the base file:").ToString(); string ext = new DirectoryInfo(SourceFilePath).Extension; string FolderPath = newForm.DS_OpenFolderDialogForm("", "Chose directory with folders:").ToString(); string SubFolderPath = newForm.DS_OpenFolderDialogForm(FolderPath, "Chose a type of folder for the base file:").ToString(); SubFolderPath = SubFolderPath.Replace(FolderPath, ""); string[] DirPathes = Directory.GetDirectories(FolderPath); string dirName; //Subfolder path Getting foreach (string dirPath in DirPathes) { dirName = new DirectoryInfo(dirPath).Name; SubFolderPath = SubFolderPath.Replace(dirName, ""); SubFolderPath = SubFolderPath.TrimStart((char)92); } //File copying foreach (string dirPath in DirPathes) { dirName = new DirectoryInfo(dirPath).Name; File.Copy(SourceFilePath, dirPath + @"\" + SubFolderPath + @"\" + dirName + ext, true); } Console.WriteLine("Done!" + "\n" + "File " + "\n" + "'" + SourceFilePath + "'" + "\n" + "has been copied to each folder: " + "\n" + "'" + SubFolderPath + "'" + "\n" + " in the directory: " + "\n" + "'" + FolderPath + "'"); Console.ReadLine(); }