复制文件/获取指定目录下的文件夹/获取指定目录下的文件
1.复制指定文件到指定位置:
public void AddFile(string sourcefile, string targetfile)
{
File.Copy(sourcefile, targetfile, true);
}
2.获取指定目录下的所有文件夹名称,返回List
public List<string> GetDirectoryInfo(string sourcePath)
{
List<string> DirectoryList = new List<string>();
DirectoryInfo TheFolder = new DirectoryInfo(sourcePath);
//遍历文件夹
foreach (DirectoryInfo NextFolder in TheFolder.GetDirectories())
DirectoryList.Add(NextFolder.Name);
return DirectoryList;
}
3.获取指定目录下的所有文件,返回List
public List<string> GetDocument(string sourcePath)
{
List<string> DocumentList = new List<string>();
DirectoryInfo TheFolder = new DirectoryInfo(sourcePath);
//遍历文件
foreach (FileInfo NextFile in TheFolder.GetFiles())
DocumentList.Add(NextFile.Name);
return DocumentList;
}