C# copy folder and files from source path to target path
程序员文章站
2022-04-29 13:41:29
static void Main(string[] args) { string sourceDir = @"E:\SourcePath"; string destDir = @"E:\Dest"; CopyDirectoriesFiles(sourceDir, destDir); Console.... ......
static void main(string[] args) { string sourcedir = @"e:\sourcepath"; string destdir = @"e:\dest"; copydirectoriesfiles(sourcedir, destdir); console.readline(); } public static void copydirectoriesfiles(string sourcedirectory, string targetdirectory) { var disource = new directoryinfo(sourcedirectory); var ditarget = new directoryinfo(targetdirectory); copyall(disource, ditarget); } public static void copyall(directoryinfo source, directoryinfo target) { directory.createdirectory(target.fullname); // copy each file into the new directory. foreach (fileinfo fi in source.getfiles()) { console.writeline(@"copying {0}\{1}", target.fullname, fi.name); fi.copyto(path.combine(target.fullname, fi.name), true); } // copy each subdirectory using recursion. foreach (directoryinfo disourcesubdir in source.getdirectories()) { directoryinfo nexttargetsubdir = target.createsubdirectory(disourcesubdir.name); copyall(disourcesubdir, nexttargetsubdir); } }
上一篇: 当前互联网已经分配的端口和服务
下一篇: linux 用户,组
推荐阅读
-
C# copy source directory files with original folder to the destination path
-
C# copy folder and files from source path to target path
-
C# copy files from source directory to destination file and rename repeated files and does not override
-
C# copy source directory files with original folder to the destination path
-
C# copy folder and files from source path to target path