我正在使用Directory.GetFiles
來查找將要複製的文件。我需要找到文件的路徑,以便我可以使用複製,但我不知道如何找到路徑。 它遍歷文件很好,但我不能複製或移動它們,因爲我需要該文件的源路徑。目錄樹陣列的路徑
這是我有:
string[] files = Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories);
System.Console.WriteLine("Files Found");
// Display all the files.
foreach (string file in files)
{
string extension = Path.GetExtension(file);
string thenameofdoom = Path.GetFileNameWithoutExtension(file);
string filename = Path.GetFileName(file);
bool b = false;
string newlocation = (@"\\TEST12CVG\Public\Posts\Temporaryjunk\");
if (extension == ".pst" ||
extension == ".tec" ||
extension == ".pas" ||
extension == ".snc" ||
extension == ".cst")
{
b = true;
}
if (thenameofdoom == "Plasma" ||
thenameofdoom == "Oxygas" ||
thenameofdoom == "plasma" ||
thenameofdoom == "oxygas" ||
thenameofdoom == "Oxyfuel" ||
thenameofdoom == "oxyfuel")
{
b = false;
}
if (b == true)
{
File.Copy(file, newlocation + thenameofdoom);
System.Console.WriteLine("Success: " + filename);
b = false;
}
}
它有更多的,但我把什麼必要了,我需要它對於我工作的工作而言,我需要的是快而不遲。 – shred1894 2012-04-26 17:49:57
你的意思是'Path.GetDirectoryName(filename)'? – mellamokb 2012-04-26 17:54:54
我需要整個路徑,而不僅僅是文件所在的文件夾。 – shred1894 2012-04-26 17:57:50