2014-02-19 96 views
-1

我想在啓動時通過xcopy複製文件。但它不起作用。複製文件與XCopy

這裏是代碼:

System.Diagnostics.ProcessStartInfo psi2 = new System.Diagnostics.ProcessStartInfo(@"xcopy.exe", @"E:\Debug\VipBat\* C:\\Users\\VCCS\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\" /s /i /y"); 
System.Diagnostics.Process.Start(psi2); 
+1

「不工作」是用戶會說什麼,之前,我深深的嘆息,讓他們瞭解更多信息。 – GolezTrol

+1

太糟糕了。你需要讓它工作。 *(提示:此評論與您的​​錯誤描述一樣有幫助)* – nvoigt

回答

0

問題:您在這裏誤用雙引號=>Startup\"

Soultion:您需要正確參數傳遞給Process.StartInfo()

你的第一個參數應該是文件名,第二個參數應該是參數。

試試這個:

System.Diagnostics.ProcessStartInfo psi2 = new 
System.Diagnostics.ProcessStartInfo(@"xcopy.exe", "E:\\Debug\\VipBat\\* \"C:\\Users\\VCCS\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\\" /s /i /y"); 
+0

您需要圍繞第二條路徑「\」,因爲它在其中有一個空格,否則將被計爲兩個不同的參數。 –

+0

它不起作用。我認爲,轉義字符存在問題,如「開始菜單」。我不知道我該如何解決它。 – user3313131

+0

@pmacnaughton:你說得對,我忽略了它。 –

0

試試這個;

Using System.IO; 

public void Copy(string filePath,string DestPath) 
{ 
    if(File.Exists(filePath)) 
    { 
     File.Copy(filePath,DestPath); 
    } 
    else 
    { 
     MessageBox.Show("The file doesn't exists.","Error") 
    } 
}