bobmiers Posted July 21, 2011 Share Posted July 21, 2011 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)\miscCode to Copy the appropriate files etc. My code for program #2: {MAKEDIR} %programfiles% (x86)\miscCode 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)\miscThanks,Bob Miers Link to comment Share on other sites More sharing options...
myselfidem Posted July 21, 2011 Share Posted July 21, 2011 (edited) You can find some help here about syntax:http://www.msfn.org/...post__p__967265Example 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 July 21, 2011 by myselfidem Link to comment Share on other sites More sharing options...
bobmiers Posted July 21, 2011 Author Share Posted July 21, 2011 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 More sharing options...
myselfidem Posted July 21, 2011 Share Posted July 21, 2011 (edited) You can try to add first for each program the subdirectory name with {MAKEDIR} and after launch the silent installation.Examples:program #1cmds[pn]=['{MAKEDIR} "%systemdrive%\\Program Files (x86)\\misc\\Mz Ultimate Tools"','"%wpipath%\\Install\\Mz7tools\\mz7o.exe" /S', ...']program #2cmds[pn]=['{MAKEDIR} "%systemdrive%\\Program Files (x86)\\misc\\Apple"','"%wpipath%\\Install\\Apple\\Apple.exe" /S', ...']program #3cmds[pn]=['{MAKEDIR} "%systemdrive%\\Program Files (x86)\\misc\\Firefox"','"%wpipath%\\Install\\Firefox\\Firefox.exe" /S', ...'] Edited July 21, 2011 by myselfidem Link to comment Share on other sites More sharing options...
bobmiers Posted July 21, 2011 Author Share Posted July 21, 2011 I think I screwed up and didn't post my last reply, so here goes againThanks, 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 More sharing options...
myselfidem Posted July 21, 2011 Share Posted July 21, 2011 (edited) The folder cannot exist before you created!The switch /S is an example!! Edited July 21, 2011 by myselfidem Link to comment Share on other sites More sharing options...
bobmiers Posted July 21, 2011 Author Share Posted July 21, 2011 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 More sharing options...
myselfidem Posted July 22, 2011 Share Posted July 22, 2011 (edited) 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.txtvendredi 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 July 22, 2011 by myselfidem Link to comment Share on other sites More sharing options...
mritter Posted July 26, 2011 Share Posted July 26, 2011 You have to use the {JSCRIPT} function. Do a search in the ChangeLog.txt for some examples. Link to comment Share on other sites More sharing options...
bobmiers Posted July 27, 2011 Author Share Posted July 27, 2011 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 MiersPS. 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now