cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dave101
Level 3

Install a File as a Different Name - Replacing an Existing File

In an InstallScript project, I need to install a renamed file. The file may already exist. Unfortunately, if the file has the read-only bit on, it cannot be deleted with DeleteFile, so a combination of DeleteFile and RenameFile does not seem to work. Example: In the build, the file is named "A", in the destination machine, it is named "B", and has the read-only bit on. (The file name is the same as the instance name in our architecture.)
Labels (1)
0 Kudos
(3) Replies
dave101
Level 3

The solution was fairly simple - change the read-only flag before deleting. Here is a working version of a function that accomplishes this:

function RenameFileOver(szDir, szFromFile, szToFile)
string szFileFound;
begin
if (FindFile (szDir, szToFile, szFileFound) = 0) then
SetFileInfo (szDir ^ szToFile, FILE_ATTRIBUTE, FILE_ATTR_NORMAL, "");
DeleteFile(szDir ^ szToFile);
endif;
RenameFile (szDir ^ szFromFile, szDir ^ szToFile);
end;
0 Kudos
dave101
Level 3

For some reason, a file on one machine leads to a return code of "Access is Denied", by DeleteFile, even after the SetFileInfo method is called. Unfortunately, I am now stuck. When I run the InstallShield-built install, it gives this error, yet I have sufficient privileges on this Windows 2000 machine to delete the file. Any ideas?
0 Kudos
SMadden
Level 6

Maybe the file is locked. Did you check if it is possible to delete it manually in Explorer?

XCopyFile with the LOCKEDFILE paramtere can handle locked files. It replaces them after a reboot. But I think it can't combine a rename operation with the copy. You would have to do that separately before the xcopy.

-Sandra
0 Kudos