C# copy source directory files with original folder to the destination path
程序员文章站
2023-11-15 17:12:28
private static void PathCopyFilesWithOriginalFolder() { int sourceFilesNum = 0; try { string sourceDir = @"E:\Source"; string destDir = @"E:\Dest"; st... ......
private static void pathcopyfileswithoriginalfolder() { int sourcefilesnum = 0; try { string sourcedir = @"e:\source"; string destdir = @"e:\dest"; string[] allsourcefiles = directory.getfiles(sourcedir, "*", searchoption.alldirectories); if (allsourcefiles != null && allsourcefiles.any()) { foreach (var sourcefilefullname in allsourcefiles) { string sourcefiledir = path.getdirectoryname(sourcefilefullname); string sourcefilerelativedir = string.empty; if (sourcefiledir.length > sourcedir.length) { sourcefilerelativedir = sourcefiledir.substring(sourcedir.length + 1); } else { sourcefilerelativedir = ""; } string destfiledir = path.combine(destdir, sourcefilerelativedir); if (!directory.exists(destfiledir)) { directory.createdirectory(destfiledir); } string destfilefullname = path.combine(destfiledir, path.getfilename(sourcefilefullname)); file.copy(sourcefilefullname, destfilefullname, true); string msg = $"sourcefilefullname:{sourcefilefullname},destfilefullname:{destfilefullname}"; console.writeline(msg); sourcefilesnum++; } } } catch(exception ex) { messagebox.show(ex.message); } finally { system.diagnostics.debug.writeline(sourcefilesnum); } }
上一篇: is_uploaded_file函数引发的不能上传文件问题
下一篇: 导航菜单的实现
推荐阅读
-
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