stonkers
1st February 2005 23:01 UTC
Change Directory if it exists
I'm having problems with a !cd that needs to happen "IF" a certain file exists (and thus the directory exists also). Here's my code:
-------------------------------------------------
IfFileExists "$INSTDIR\folder\file" +1 skip1
!cd "$INSTDIR\folder"
skip1:
;stuff...
-------------------------------------------------
I'm getting a compiler error because the directory doesn't exist. Is there a way to do this?
Thanks,
Eric
Joel
2nd February 2005 04:26 UTC
try IfFileExists with a folder... I think they use the same API for files and folders:
Name boo
Caption boo
OutFile boo.exe
XPSTyle on
ShowInstDetails show
Section
IfFileExists $WINDIR 0 +3
StrCpy $0 "Folders exists"
Goto Exit
StrCpy $0 "OMG! You don't have windir :S"
Exit:
DetailPrint $0
SectionEnd
Comm@nder21
2nd February 2005 14:59 UTC
IfFileExists "$INSTDIR\folder\file" +1 skip1
!cd "$INSTDIR\folder"
you mixed some things up ...
"!cd" is a compiletime command
"$INSTDIR" is a runtime variable
"IfFileExists" is a runtime command
stonkers
2nd February 2005 19:40 UTC
I don't get it Comm@nder21, you put the same code as me there. It won't compile "because" !cd is a compiletime command. Is there a way to do what I'm trying to do (i.e. a way to change directories at runtime)?
Thanks,
Eric
Afrow UK
2nd February 2005 20:56 UTC
SetOutPath...
-Stu
Comm@nder21
2nd February 2005 21:05 UTC
i just copied your code and explained it to you.
i never posted a fix :)
now, here is one, if you DO WANT it to perform at RUNTIME:
IfFileExists "$INSTDIR\folder\*.*" 0 +2 ; will jump 'over' the setoutpath command
SetOutPath "$INSTDIR\folder" ; will set the runtime var $OUTDIR to $INSTDIR\folder, all recursive file commands use this path as root. also do execute and shortcut commands (as working dir)
stonkers
2nd February 2005 22:23 UTC
Thanks Comm@nder21 and Afrow UK! I've seen that command but knew not what it was doing. Live long and prosper!