[英]how to copy multiple files from one directory to another with progressBar in c# window form
[英]How do i copy files from one directory to another directory?
string[] s = Directory.GetFiles(t, "*.txt",SearchOption.AllDirectories);
for (int i = 0; i < s.Length; i++)
{
File.Copy(s[i],
}
File.Copy會將文件復制到另一個文件名。 我想保持相同的文件名,只需將它們從一個目錄復制到另一個目錄即可。
用這個:
File.Copy(s[i], "c:\\anotherFolder\\" + Path.GetFileName(s[i]));
您可以像這樣很好地做到:
Directory.GetFiles("c:\\temp", "*.txt", SearchOption.AllDirectories) // get the files
.Select(c => new FileInfo(c)) // project each filename into a fileinfo
.ToList() // convert to list
.ForEach(c => c.CopyTo("d:\\temp\\" + c.Name)); // foreach fileinfo, copy to the desired path + the actual file name
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.