cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jchristman
Level 8

Installscript Move Directory

I am looking for a way in Installscript to move a directory and all of its contents.

example:

move "C:\MyAPP" to "C:\Program Files\MyAPP"

I was going to use something like this, but I do not think this is the best way.

XCopyFile("C:\MyAPP","C:\Program Files\MyAPP",INCLUDE_SUBDIR);
DELETEDIR("C:\MyAPP");
Labels (1)
0 Kudos
(23) Replies
RobertDickau
Flexera Alumni

I haven't tried it, but perhaps see if RenameFile works? It evidently doesn't work if the source and target are on different drives, but you might give it a shot if the two directories are on the same drive.
0 Kudos
jchristman
Level 8

thank you for the help, but I do need it to work across drives

It appears my XCopyFile does not work properly.

I need something that can do a copy or move from Drive to Drive.

I can do a copy then do a delete to remove the original files.
0 Kudos
RobertDickau
Flexera Alumni

What does the failing XCopyFile call look like? What is the error or return code, if any?
0 Kudos
jchristman
Level 8

It is not actually throwing an error, it just does not seem to be doing the copy. I am wanting to copy the directory subdir2 to a new path. subdir2 does not exists at the new path.

Here is what I am using.


XCopyFile(svString^"subdir\\subdir2",svInstLoc^"subdir2",INCLUDE_SUBDIR);
0 Kudos
dan_galender
Level 10

I think what Robert is suggesting is you do something along the following

nReturn = XCopyFile(svString^"subdir\\subdir2",svInstLoc^"subdir2",INCLUDE_SUBDIR);


after declaring nReturn, of course.

Then after that call, look at the value of nReturn. Return codes from XCopyFile are (somewhat) documented in the help file for that function call.
0 Kudos
jchristman
Level 8

thank you, I have made the changes to get the code here is what I get in my log.

Located: C:\MyAPPoldloc
Moving: C:\MyAPPoldloc\1 >> E:\Program Files\MyAPPNewLoc\1
ReturnCode: -2147024894
0 Kudos
RobertDickau
Flexera Alumni

What message do you get if you pass that large negative number to FormatMessage?
0 Kudos
jchristman
Level 8

Here is what I get.

ReturnMessage: The system cannot find the file spedified.

Is this because I am trying to copy directories instead of files.

I know before it runs these folders exist.
C:\MyAppoldloc\1
E:\Program Files\MyAppNewLoc\subdir
and
here is my XCopy.

XCopyFile(svString^szEnt,svInstLoc^"subdir"^szEnt,INCLUDE_SUBDIR);

which gives me an entry in the log of
Moving: C:\MyAPPoldloc\1 >> E:\Program Files\MyAPPNewLoc\subdir\1
0 Kudos
jchristman
Level 8

Is there any other way to move directories.
0 Kudos
RobertDickau
Flexera Alumni

What is your definition of szEnt? Does it make any difference if you include the "*.*" file name mask?
0 Kudos
dan_galender
Level 10

Have you tried appending a "^ *.*" after the source path?

[Sorry, Robert beat me by less than a minute.]
0 Kudos
jchristman
Level 8

Thank you both, I add ^"*.*" and that worked.

So now my statement looks like so.

XCopyFile(svString^szEnt^"*.*,svInstLoc^"subdir"^szEnt,INCLUDE_SUBDIR);
0 Kudos
jchristman
Level 8

I am doing a DeleteDir(svString,ALLCONTENTS) and it does not seem to be doing anything.

I get a return code of -1 and there is no message
0 Kudos
dan_galender
Level 10

And what is the value of svString?
0 Kudos
jchristman
Level 8

svString = "C:\MyAPP"; // location of old manual install.
DeleteDir(svString,ALLCONTENTS);
0 Kudos
dan_galender
Level 10

I don't have time right now to run a test, but try adding a trailing backslash to the end of the path and see if that helps.
0 Kudos
jchristman
Level 8

I tried that and it did not work. So I read up on DeleteDir some more and if there is a single file set to readonly it will fail.

I am looking for anothe method to delete a folder and all of its contents or set the folder and all files so they are not read only.
0 Kudos
dan_galender
Level 10

Maybe you could do a LaunchAppAndWait on a CMD.exe command that runs the ATTRIB command on that folder specifying the -R and /S parameters.
0 Kudos
jchristman
Level 8

I got the installer to start cmd.exe but I cannot figure out how to pass the command into it.

I tried

LaunchAppAndWait(WINSYSDIR^"cmd.exe","Linethat goes to the prompt",WAIT);

It opens the command box and waits but it does not execute the line, any thoughts on how to get the string into the command prompt so it runs.
0 Kudos
dan_galender
Level 10

It would have been interesting to see the contents of "Linethat goes to the prompt". But maybe you can try:

LaunchAppAndWait(WINSYSDIR ^ "Cmd.exe", "/c Attrib -r " + svString + "\\*.* /s", WAIT);

Where svString is the directory you showed earlier (which has no trailing backslash).
0 Kudos