[英]Copy file from source directory to destination C#
我想將文件從源文件夾復制到我的目的地。 夾
位置/ URL(表中列的名稱)我從這里獲取。GetDataByGeneralRoot();
現在,我想那些文件從URL復制到一個新的目錄。
我所做的是:
DataSet1.T_DocumentsDataTable docTab = doc.GetDataByGeneralRoot();
string gerneralRootPath = docTab.Rows[0]["URL"].ToString();
gerneralRootPath = gerneralRootPath.Remove(gerneralRootPath.IndexOf("PDF") + 4);
string datadirectory = "//ch-s-0001535/G/inetpub/DocAddWeb/DataSource/";
string final = datadirectory + gerneralRootPath;
foreach (string path in Directory.GetFiles(final, "*.*", SearchOption.AllDirectories))
{
string t = path.Substring(path.IndexOf("\\") + 1);
File.Copy(t, t.Replace(final + t, rootFolderAbsolutePath));
}
我的問題/問題是,我怎么能說我想只是我從我的方法GetDataByGeneralRoot得到了從URL文件,而不是所有的文件,什么是現在發生的事情。
我想你想要這樣的東西
public void copyAll(DataSet ds, Doc doc, string rootPath, string rootTargetPath)
{
ds.T_DocumentsDataTable docTab = doc.GetDataByGeneralRoot();
string datadirectory = "//ch-s-0001535/G/inetpub/DocAddWeb/DataSource/";
string final = datadirectory + rootPath;
foreach (var row in docTab.Rows)
{
var sourceFile = "//ch-s-0001535/G/inetpub/DocAddWeb/DataSource/" + row["URL"].ToString();
string targetPath = rootTargetPath + row["URL"].ToString();
File.Copy(sourceFile, rootTargetPath);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.