出於某種原因,安裝此程序的用戶在點擊按鈕時沒有任何反應。另外,如果我嘗試並捕獲,它說該文件已經存在,並且它不。子文件夾是,但不是文件。哪裏不對?這裏是我的代碼:將文件移動到C#中的子文件夾的麻煩?
string pathUser4 = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string pathDownload4 = (pathUser4 + @"\Downloads\");
string sourceFile = pathDownload4 + listBox1.Text;
string pathdoc5 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string pathDownload5 = (pathdoc5 + @"\iracing\setups\");
string destinationFile = pathDownload5 + comboBox1.Text;
File.Move(sourceFile, destinationFile);
}
catch { }
if (comboBox1.Text == "Select File Destination")
{
MessageBox.Show("Please Select A Destination Folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
對於編碼風格,請使用Path.Combine創建路徑。 'string pathDownload4 = Path.Combine(pathUser4,「Downloads」);' – MichelZ
由於某種原因不起作用。它給了我錯誤的目錄,並且由於某種原因取消了用戶配置文件....那不是什麼問題......我知道 –
我知道這不是錯誤的部分,只是爲了更好的編碼風格。 在使用Path.Combine時不要使用斜槓,我想。 (所以你的@「\ Downloads」變成「Downloads」) – MichelZ