我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;
}
}