Spread the love! TechSpot Tech Gift Shortlist 2017

Help creating folder and version search in batch file

By vitamin1 ยท 5 replies
Jan 6, 2012
Post New Reply
  1. Hello,

    how do i create a batch file that will search for a specific folder, then the version of the program in the folder, and create a if else statement. for example if the version is 5.1 then go to do this, if it is lower then do this

    please help
  2. gbhall

    gbhall TechSpot Chancellor Posts: 2,431   +77

    I don't think you would be able to easily achieve that in a batch file. A windows-compatible programming language is probably required. You need to be able to call features of the Windows API, and you can do this in many languages, such as C,C++, delphi, visual basic, visual foxpro, pascal, even html/asp.

    The advantage of such an approach is you can end up with a standard-looking windows application to interface with. In other words, you can key your 'specific folder' into an input box and your 'do this' and 'do that' are also part of a pre-defined routine which in turn, may require variable parameters to be input.

    Not to put too fine a point on it, are you sure you want to do this thing so many times? As it may require you to devote several weeks to learning to program, compile, test, create install utilities. Or would it not make more sense to just use the built-in windows search facilities and cut-paste on a few occasions?
  3. jmjsquared

    jmjsquared TS Booster Posts: 145

    Not being a coder, I find this resource very useful: http://www.robvanderwoude.com/batchcommands.php Be sure to look at the NOTES near the bottom for a links to more examples.

    I do know that there is a CALL statement which will allow you to run a BATCH within a BATCH and in the same environment. Perhaps you could "string together" several such Files to accomplish your task.

    Here is a Batch File builder that offers a trial version that I think allows you to save any created Files. http://www.drbatcher.com/product-information.php

    Hope this interjection proves helpful.
  4. vitamin1

    vitamin1 TS Rookie Topic Starter

    this will be done on mutilple machines, and i cannot do it physically on all. thats why i want to create this . So i can run it once and thats it.
    lets say i wanted to do this for Itunes. I would want upon start of machine to check if folder exist, then the version there after to determine if there is a upgrade needed if so do this. If not just exit out.
  5. gbhall

    gbhall TechSpot Chancellor Posts: 2,431   +77

    What you want to do is identical to the work a windows installer does.

    That needs a specialised script to drive it, which is only a bit short of a programming language, but certainly has the capabilities you need.

    There are several commercial installers available and one or two free ones. The only one I have used is InstallShield. I cannot recommend any free ones as I have never used any, but if you are determined to do this thing, that is definitely the way to go.
  6. jobeard

    jobeard TS Ambassador Posts: 10,880   +903

    Three requirements:

    repeated search via a bat file (better choice a script)
    • user selected source folder
    • output to a file
    • file name and versioning filters are needed to be selected

    Instead of old-world BATs, imo might as well learn a scripting language
    that will take you much further into the future - - like PHP

    PHP is portable to other systems {mac, pc, linux} while keeping the grammar identical.

    PHP code is easy to read and write; eg the IF THEN ELSE reads
    if ($thisVariable > 1234) {
        /* do the TRUE case */
    } else {
       /* do the FALSE case */
    compounding test like A & B then do can be written several ways but this
    nested series will test each condition ONCE and stop testing on the first failure
    (so it's fast)
    if ($filename == "foo.exc") {
    	switch ($version) {    /* testing version as a character string */
    		case "1.0":
    			/* do the foo.exc version 1.0 thing */
    		case "2.1":
    			/* do the foo.exc version 2.1 thing */
    		case "2.2":
    			/* do the foo.exc version 2.2 thing */
    			/* case not understood */
    } else {
       /* proper file not found so ignore version tests */
    your invocation might look like
    myscript searchDirName fileNamePattern outputFilePathandFileName​

    Placing myscript on a mapped drive would allow it to be maintained in one place
    but used everywhere (assuming each client system had PHP also installed)

    Yea, you need to install PHP globally but many things also have global resource requirements.

    Just my $0.02

    btw: the help files for PHP come as HTML files too :)

Similar Topics

Add your comment to this article

You need to be a member to leave a comment. Join thousands of tech enthusiasts and participate.
TechSpot Account You may also...