Archive: Change Directory if it exists


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


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

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


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


SetOutPath...

-Stu


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)

Thanks Comm@nder21 and Afrow UK! I've seen that command but knew not what it was doing. Live long and prosper!