PDA

View Full Version : Rename a file



kyungmo
06-27-2005, 04:47 PM
I want to rename a file during installation. How do I do it? The file is not in my InstallDir.

I am using Basic MSI project and rename a file in my install script custom action.

RobertDickau
06-28-2005, 08:18 AM
Is it that you want to avoid using a script custom action? You can use the MSI MoveFile table (available in the Direct Editor view) to rename a file at run time. The MSI Help Library page "MoveFile Table" describes the syntax.

kyungmo
06-28-2005, 12:30 PM
Thanks for reply, Robert.

I can rename a file during installation by using the MSI MoveFile table.
How do I put the file name back during uninstallation? Should I write custom code to do it? Is there any way I could use MSI MoveFile table with condition?

MartinMarkevics
06-28-2005, 02:32 PM
You probably have to create a custom action to do move the file back on uninstall. Because the MoveFile table is tied to a component state, unless you had a component being installed, while the rest of your install is being uninstalled, it's not possible to use the MoveFile table.

kyungmo
06-28-2005, 04:38 PM
I have wrote a cutom code to change file name back, but following my custom code doen't work.

//INSTALLDIR retruns C:\xyz\
if( RenameFile (INSTALLDIR + "abc\123.bak",INSTALLDIR + "abc\123.exe") == 0) then
MessageBox("success",INFORMATION);
else
MessageBox("fail",INFORMATION);
endif;

I am wondering about the file path. The path for RenameFile must be like "C:\\xyz\\abc\\123.bak"
How do get right format of the path? Should I do some string manipulaltion?

kyungmo
06-29-2005, 09:14 AM
I have tried several different path format, but it seems like RenameFile function is not working at all. Is there any idea?

RobertDickau
06-29-2005, 10:15 AM
Building the path with INSTALLDIR^"dir\\filename.ext" should do it; if you print that string in a message box, does it look right?

kyungmo
06-29-2005, 04:57 PM
Fixed problem. Instead of using INSTALLDIR in the path, I need to define a path at the beginning of my custom code. It seems like Rename funtion does not work if you are using INSTALLDIR in the path.


#define TARGET INSTALLDIR

.....

Rename(TARGET^"abc\\123.bak",TARGET^"abc\\123.exe")