Jump to content

Testing if Folder Exists code syntax


Recommended Posts

Testing if Folder Exists code

Please forgive me for asking such a simple question. I've started using WPI a couple of months ago. I think that it is a great program that really saves a lot of time.

I have several freeware programs that don't have a normal install method – they are standalone EXE's. I normally create a subdirectory in the Program Files/Program Files (x86) subdirectories. I then place the programs there and create a shortcut to them. Creating the subdirectory, putting the programs there and creating the deskop shortcuts is easily accomplished via WPI.

My desire is to avoid the "failed" message for command 1, by testing for the existence of the subdirectory, when I attempt to add a second program into the subdirectory via WPI.

My code for program #1:

{MAKEDIR} %programfiles% (x86)\misc

Code to Copy the appropriate files etc.

My code for program #2:

{MAKEDIR} %programfiles% (x86)\misc

Code to Copy the appropriate files etc.

What I need is the correct syntax for using the FolderExists function:

!FolderExists("%programfiles%\\ (x86)\\misc") {MAKEDIR} %programfiles% (x86)\misc

Thanks,

Bob Miers

Link to comment
Share on other sites


You can find some help here about syntax:

http://www.msfn.org/...post__p__967265

Example with Mz 7 Optimizer:


prog[pn]=['Mz 7 Optimizer 5.1'];
uid[pn]=['MZ7OPTIMIZER51'];
ordr[pn]=[19];
dflt[pn]=['yes'];
forc[pn]=['no'];
bit64[pn]=['no'];
cat[pn]=['Applications'];
pfro[pn]=['no'];
cmds[pn]=['{MAKEDIR} "%systemdrive%\\Program Files\\Mz Ultimate Tools\\Mz 7 Optimizer\\Languages"','{FILECOPY} "%wpipath%\\Install\\Mz7tools\\French.xml" "%systemdrive%\\Program Files\\Mz Ultimate Tools\\Mz 7 Optimizer\\Languages\\"','"%wpipath%\\Install\\Mz7tools\\mz7o.exe" /Lang=French /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-','{JSCRIPT}=CreateShortcut("Mz 7 Optimizer"%comma%"C:\\Program Files\\Mz Ultimate Tools\\Mz 7 Optimizer\\Mz7Optimizer.exe"%comma%""%comma%"C:\\Program Files\\Mz Ultimate Tools\\Mz 7 Optimizer\\Mz7Optimizer.exe"%comma%""%comma%"Desktop"%comma%"")'];
desc[pn]=['Mz 7 Optimizer 5.1'];
pn++;

Edited by myselfidem
Link to comment
Share on other sites

Thank you myselfidem for your reply.

As usual, I failed to fully explain my problem.

Your sample was helpful but doesn't address my problem, so I'll try once more to explain.

I have multiple programs that I want to install into the SAME subdirectory. The Command code is quite similar - only the program name is different.

The 1st install goes well without any "failed" messages. However, WPI issues a "failed" notification on the when the second (or later) {MAKEDIR} command is executed.

What I want to accomplish is to use the FolderExists function to test if the target subdirectory already exists. If it does then simply go onto the next command, otherwise create the subdirectory. In other words, use an IF/Then structure.

Thanks,

Bob Miers

Link to comment
Share on other sites

You can try to add first for each program the subdirectory name with {MAKEDIR} and after launch the silent installation.

Examples:

program #1

cmds[pn]=['{MAKEDIR} "%systemdrive%\\Program Files (x86)\\misc\\Mz Ultimate Tools"','"%wpipath%\\Install\\Mz7tools\\mz7o.exe" /S', ...']

program #2

cmds[pn]=['{MAKEDIR} "%systemdrive%\\Program Files (x86)\\misc\\Apple"','"%wpipath%\\Install\\Apple\\Apple.exe" /S', ...']

program #3

cmds[pn]=['{MAKEDIR} "%systemdrive%\\Program Files (x86)\\misc\\Firefox"','"%wpipath%\\Install\\Firefox\\Firefox.exe" /S', ...']

Edited by myselfidem
Link to comment
Share on other sites

I think I screwed up and didn't post my last reply, so here goes again

Thanks, I see what you are suggesting.... put each of my programs within its own subdirectory under my "misc" subdirectory (then the {MAKEDIR} command would always work without the "failed" message. Wouldn't that work with out the "/S" option,?

To continue my education, can you please explain how one uses the "FolderExists" logical function.

Bob Miers

Link to comment
Share on other sites

I'm aware that FolderExists would return a False prior to the subdirectory being created and True if the subdirectory is there . However, if one were to use the negate function ("!") in front of FolderExists, then the final result should be True, so then the {MAKEDIR} should be executed. This a standard method in a variety of other languages.

Link to comment
Share on other sites

After testing works like this:

Example:


prog[pn]=['mz7Perso'];
uid[pn]=['MZ7PERSO'];
ordr[pn]=[22];
dflt[pn]=['yes'];
forc[pn]=['no'];
bit64[pn]=['no'];
cat[pn]=['Applications'];
pfro[pn]=['no'];
cmds[pn]=['{MAKEDIR} "C:\\Program Files\\Mz Ultimate Tools\\MZ"'];
cond[pn]=['FolderExists("C:\\Program Files\\Mz Ultimate Tools")'];
desc[pn]=['mz7Perso'];
pn++;

WPI_Log.txt

vendredi 22 juillet 2011 08:02:46

Programme: mz7Perso

ID unique: MZ7PERSO

Ordre: 000022

Catégorie: Applications

vendredi 22 juillet 2011 08:02:46 - cmd1 Succès (Code de retour 0): CMD /C md "C:\Program Files\Mz Ultimate Tools\MZ"

vendredi 22 juillet 2011 08:02:47 - Installation terminée.

Edited by myselfidem
Link to comment
Share on other sites

mritter:

Thanks for your suggestion. It was quite helpful. After a bit of testing to get the syntax correct, I came up with this statement:

{JSCRIPT}=if (!FolderExists("%ProgramFiles(x86)%\misc\")) RunCmd('cmd /c mkdir "%ProgramFiles(x86)%\misc\"',false,true)

Now, if the folder doesn't exist, the command creates it and issues the "Success" message. If the folder does exist, the command also issues the "Success" message. Just what I wanted.

I'm now off to creating the shortcuts...

Once again, thanks.

Bob Miers

PS. During this process, I discovered another system variable... i.e. %ProgramFiles(x86)%. It doesn't show up in the ALT+G command variables.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...