Reputation: 18848
I want to copy list of files from Source directory to destination directory.
Source\a.bat
Source\test\a.bat
Dest\a.bat
Dest\test\a.bat
Something I am trying to do
public static void ReplicateFile(List<string> files, ref string destinatonFilePath){
foreach (var file in files)
{
var directory = Path.GetDirectoryName(file);
var fileName = Path.GetFileName(file);
var destDir = Path.Combine(destinatonFilePath, directory);
if (!string.IsNullOrEmpty(destDir))
CreateDirectory(new DirectoryInfo(destDir));
if (fileName != null) File.Copy(file, Path.Combine(destDir, fileName), true);
}
}
I am newbie to C#, so apologize for silly mistakes. Any elegant way to do the same?
Since List of files
contains the below structure a.bat
, test\a.bat
.
Any directory function to create the same structure?
Upvotes: 0
Views: 574