本文介绍了将多个文件从目录复制到某个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! string date = DateTime.Today.ToString( yyyyMMdd); string dirPath = @ \\ path; string backup = @ \\ path; string backupfile = Path.Combine(备份,日期); string filepattern1 = LS _ * .txt ; string filepattern2 = PS _ * .txt ; string filepattern3 = MS _ * .txt ; string [] filesHD =目录。 GetFiles(dirPath,filepattern1); string [] filesDT = Directory.GetFiles(dirPath,filepattern2); string [] filesTD = Directory.GetFiles(dirPath,filepattern3); 这里我想将filesHD Array,filesDT Array和filesTD Array中的所有文件复制到备份文件中。怎么可能?解决方案 试试这样.. string date = DateTime.Today.ToString( YYYYMMDD); string dirPath = @ D:\\ \\Files\; string backup = @ D:\\ \\Files\output\; string backupfile = Path.Combine(备份,日期); string filepattern1 = LS _ * .txt ; string filepattern2 = PS _ * .txt ; string filepattern3 = MS _ * .txt ; string [] filesHD = Directory.GetFiles(dirPath,filepattern1); string [] filesDT = Directory.GetFiles(dirPath,filepattern2); string [] filesTD = Directory.GetFiles(dirPath,filepattern3); Directory.CreateDirectory(backupfile); ; filesHD.ToList()。ForEach(k = > File.Copy(k,Path.Combine(backupfile,Path.GetFileName(k))) ); filesDT.ToList()。ForEach(k = > File.Copy(k,Path.Combine(backupfile,Path.GetFileName(k))) ); filesTD.ToList()。ForEach(k = > File.Copy(k,Path.Combine(backupfile,Path.GetFileName(k))) ); Console.WriteLine( done); 注意:照顾验证:) 参考:文件 - >复制,删除,移动 [ ^ string date = DateTime.Today.ToString("yyyyMMdd"); string dirPath = @\\path; string backup = @\\path; string backupfile = Path.Combine(backup,date); string filepattern1 = "LS_*.txt"; string filepattern2 = "PS_*.txt"; string filepattern3 = "MS_*.txt";string[] filesHD = Directory.GetFiles(dirPath, filepattern1); string[] filesDT = Directory.GetFiles(dirPath, filepattern2); string[] filesTD = Directory.GetFiles(dirPath, filepattern3);here I want to copy all the files from filesHD Array, filesDT Array and filesTD Array to the backup file. How could it be possible ? 解决方案 Try like this..string date = DateTime.Today.ToString("yyyyMMdd"); string dirPath = @"D:\Files\"; string backup = @"D:\Files\output\"; string backupfile = Path.Combine(backup,date); string filepattern1 = "LS_*.txt"; string filepattern2 = "PS_*.txt"; string filepattern3 = "MS_*.txt"; string[] filesHD = Directory.GetFiles(dirPath, filepattern1); string[] filesDT = Directory.GetFiles(dirPath, filepattern2); string[] filesTD = Directory.GetFiles(dirPath, filepattern3); Directory.CreateDirectory(backupfile); ; filesHD.ToList().ForEach(k => File.Copy(k, Path.Combine(backupfile, Path.GetFileName(k)))); filesDT.ToList().ForEach(k => File.Copy(k, Path.Combine(backupfile, Path.GetFileName(k)))); filesTD.ToList().ForEach(k => File.Copy(k, Path.Combine(backupfile, Path.GetFileName(k)))); Console.WriteLine("done");note: Take care of validations :)Reference : File-> copy,delete,move[^] 这篇关于将多个文件从目录复制到某个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-05 03:45