Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Testing if Folder Exists code syntax

Featured Replies

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

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

  • Author

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

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

  • Author

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

The folder cannot exist before you created!

The switch /S is an example!!

Edited by myselfidem

  • Author

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.

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

You have to use the {JSCRIPT} function. Do a search in the ChangeLog.txt for some examples.

  • Author

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.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.