1.前言
以程式控制將原始檔案夾路徑下的所有檔案複製到指定檔案夾路徑下。
2.說明
首先取得原始檔案夾路徑下的所有檔案名稱
private FileInfo[] GetFileList(string path)
{
FileInfo[] fileList = null;
if (Directory.Exists(path))
{
DirectoryInfo di = new DirectoryInfo(path);
fileList = di.GetFiles();
}
return fileList;
}
將檔案複製到指定檔案夾路徑下
private void CopyFiles(string remotePath, string localPath)
{
FileInfo[] file = GetFileList(remotePath);
for (int i = 0; i < file.Length; i++)
{
string fileName = remotePath + @"\" + file.GetValue(i).ToString();
string desFileName = localPath + @"\" + file.GetValue(i).ToString();
File.Copy(fileName, desFileName, true);
System.Threading.Thread.Sleep(500);
}
}
3.應用
CopyFiles(@"D:\a", @"D:\b");
MessageBox.Show("Batch copy files completed!");
文章標籤
全站熱搜
