我正在使用IExpress制作一个安装程序来解压文件,创建一个文件夹并将文件移动到文件夹中。
但是,在选择安装时运行哪个程序时,我只能使用批处理文件使其工作:
@ECHO OFF
MD C:\PlugInFolder
MOVE /Y "%USERPROFILE%\AppData\Local\Temp\IXP000.TMP\*.png" C:\PlugInFolder
MOVE /Y "%USERPROFILE%\AppData\Local\Temp\IXP000.TMP\PlugIn.dll" C:\PlugInFolder
MOVE /Y "%USERPROFILE%\AppData\Local\Temp\IXP000.TMP\PlugIn2021.addin" C:\ProgramData\Autodesk\Revit\Addins\2021
MOVE /Y "%USERPROFILE%\AppData\Local\Temp\IXP000.TMP\PlugIn2022.addin" C:\ProgramData\Autodesk\Revit\Addins\2022是否可以转而运行exe文件?我尝试了以下C#-代码(仅针对其中一个文件),但它只创建文件夹,不移动文件:
// Creating paths
string path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string folderName = "PlugInFolder";
string pathString = Path.Combine(path, folderName) + "\\PlugIn.dll";
string tempName = Path.GetTempPath() + "IXP000.TMP\\";
string fileName = "PlugIn.dll";
string filePath = tempName + fileName;
// Creating new directory
Directory.CreateDirectory(pathString);
// Moving files from temp folder
File.Move(filePath, pathString);发布于 2022-10-31 22:49:14
您的代码中有几个输入。正确地使用Path.Combine (这是一个强大的命令)可以正常工作:
// Creating paths
string source = Path.Combine(Path.GetTempPath(), "IXP000.TMP");
string dest1 = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string dest2 = "PlugInFolder";
string dest = Path.Combine(dest1, dest2);
// Creating new directory
// Directory.CreateDirectory(dest);
// Don't create the directory, because we will use Directory.Move
// and it would raise an exception "Directory already exists"
// Moving files from temp folder to destination
// File.Move is meant to move one file at a time.
// For an entire directory, use Directory.Move which can also be used for renaming the directory.
Directory.Move(source, dest);顺便说一句,在用户配置文件dir中放置应用程序是一种选择吗?否则,您可以使用:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)它将是C:\Users\yourName\AppData\漫游,例如在Windows 11中。
https://stackoverflow.com/questions/74260178
复制相似问题