我正在使用 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);
uj5u.com熱心網友回復:
您的代碼中有一些拼寫錯誤。以下是正確使用 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);
而且,順便說一句,將應用程式放在用戶組態檔目錄中是一種選擇嗎?否則,您可以使用:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
例如在 Windows 11 中,這將是 C:\Users\yourName\AppData\Roaming。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/525597.html
標籤:C#批处理文件速卖通
上一篇:在GoogleAppScript中將兩個范圍合并為一個范圍
下一篇:元素之間的填充,但不在側面
