System.IO.File.Move() 不移动文件



我正在尝试制作一个简单的exe,当打开它时,它会将自己移动到我的文档文件夹中,但当我打开它时它不会这样做,我能做什么?

string fileName = "installer.exe";
string strExeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string strWorkPath = System.IO.Path.GetDirectoryName(strExeFilePath);
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFileMove = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
System.IO.File.Move(sourceFile, destFileMove);

File.Move(string, string)接受了2个文件名,因此您的第二个参数不正确:您必须传递目标完整文件名,而不是传递目标文件夹。

如果你想保留以前的文件名,可以这样做:

string destFileMove = Path.Combine( 
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
fileName);

最新更新