c# - Copy everything in a Directory and rename copied Files -
I try to copy everything in a folder, in this case "sourceFolder" to "targetFolder".
Let's say that "sourcefolder" will contain two files and 2 subfolders with an additional file: (I try to show it)
// sourceFolder //├File1.txt / /├File2.txt // ├Subfolder1 // | └File3.txt // | // └Subfolder2 // └File4.txt
Now I'm trying to copy all the files and subfolders of "targetFolder" from "sourceFolder", subfolders will be title and files But I'd like to add "a" in front of "file" (Exaple: "aFilex.txt") that you want to meet:
// targetFolder // ├aFile1.txt // ├aFile2 .txt // ├Subfolder1 // | └aFile3.txt // | // └Subfolder2 // └aFile4.txt
Current code:
string [] sourceDirectoryFiles = Directory.GetFiles (sourceFolderTextbox.Text); String [] sourceDirectorysubfolders = Directory.GetDirectories (targetFolderTextbox.Text); String sourcedirectory = sourceFolderTextbox.Text; String targetdirectory = targetFolderTextbox.Text; If (directory.Exists (sourceDirectorysubfolders [0])) {foreach (string source filepath in source.directorysubfolders) {if !! Directory.Exists (sourceFilePath)) {Directory.Creative Directory (sourceFilePath.Replace (sourcedirectory, targetdirectory)); }}} Foreach (in the source source filepoint source directoryfile) {string newsourcefilePath = String.Empty; String newfilePath = String.Empty; String filename = System.IO.Path.GetFileName (sourceFilePath); NewsourcefilePath = sourcedirectory + "\\" + filename; I hope, I asked the question :) otherwise I will answer your questions :)
I am not good at English or in programming so creative criticism is welcome. :)
Improve the solution It is in line with your requirements Hope it will be helpful.
Zero Copy (string source path, string target path) {foreach (directory. Directory) (string directory, "*", search option. String directories in all directories). Create Directory (Change HeartPath (sourcePath, targetPath)); String nepath; Foreign currency (string srcpath) Directory.GetFiles (sourcePath, "*. *", SearchOption.All Directories)) {newPath = srcPath.Replace (sourcePath, targetPath); Newpath = newPath.Insert (newPath.LastIndexOf ("\\") + 1, "A"); // Prefixing 'A' newPath = newPath + ".example"; File.Copy (srcPath, newPath, true); }}
Comments
Post a Comment