0

I'm making an installer using IExpress to unpack the files, create a folder and move the files to the folder.

However, when choosing which program to run upon installation I can only get it to work using a batch-file:

@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

Is it possible to run an exe file instead? I've tried the following C#-code (for one of the files only) but it only creates the folder and doesn't move the files:

// 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);

Mathias
  • 5
  • 2
  • Yes, it will work, I've just tried, and please have a look at the solution below, I corrected your code. – Fredy Oct 31 '22 at 23:00

1 Answers1

0

There are a few typos in your code. Here's what could work, correctly using Path.Combine which is a powerful command:

// 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);

And, by the way, is it a choice to put an application in the user profile dir? Otherwise, you may use:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

which would be C:\Users\yourName\AppData\Roaming for example in Windows 11.

Fredy
  • 532
  • 3
  • 11
  • Thank you - this worked perfectly! However, I ended up sticking with the CreateDirectory and deleting the directory beforehand if it exists such that a new version of the installer would be able to overwrite the contents of the folder. – Mathias Nov 02 '22 at 11:43
  • @Mathias thank you for the feedback! Happy to see you achieved your aim :) – Fredy Nov 02 '22 at 13:10