c#如何copy指定文件到目錄
我想copy目錄下指定文件到目的目錄,如:
在A目錄下所有命名為:TEXT的文件都要copy到另一個目錄B
--------------------编程问答--------------------
--------------------编程问答-------------------- System.IO.File --------------------编程问答-------------------- System.IO.DirectoryInfo _SourceDirect = new System.IO.DirectoryInfo(@"C:\A";);
System.IO.File.Copy(@"C:\Text.txt", @"D:\text.txt", true);
System.IO.DirectoryInfo _PurposeDirect = new System.IO.DirectoryInfo(@"C:\B");
System.IO.FileInfo[] _FileList =_SourceDirect.GetFiles();
for(int i=0;i!=_FileList.Length;i++)
{
if(_FileList[i].Name.ToUpper().IndexOf("Text")==0) //条件你可以自己改
{
System.IO.File.Copy(_FileList[i].FullName, _PurposeDirect+"\\"+_FileList[i].Name);
}
} --------------------编程问答--------------------
public void CopyFile(string path, string newPath)--------------------编程问答--------------------
{
string[] files = Directory.GetFiles(path);
for (int i = 0; i < files.Length; i++)
{
FileInfo fi = new FileInfo(files[i]);
if (fi.Extension.ToLower() == ".text")
{
File.Copy(fi.FullName, newPath + "\\" + fi.Name);
}
}
}
--------------------编程问答-------------------- copy都沒有執行啊
System.IO.DirectoryInfo _SourceDirect = new System.IO.DirectoryInfo(@"C:\A";);
System.IO.DirectoryInfo _PurposeDirect = new System.IO.DirectoryInfo(@"C:\B");
System.IO.FileInfo[] _FileList =_SourceDirect.GetFiles();
for(int i=0;i!=_FileList.Length;i++)
{
if(_FileList[i].Name.ToUpper().IndexOf("Text")==0) //条件你可以自己改
{
System.IO.File.Copy(_FileList[i].FullName, _PurposeDirect+"\\"+_FileList[i].Name);
}
}
补充:.NET技术 , C#