Search for file/folder using batch

By lavo140
Jul 17, 2008
  1. Hi all, i am trying to get a simple batch file to find the path to a certain file, which may vary, but the file name remains the same inside different folders.. would this be possible using batch or would there be a way to do it using a different method?

    Also would it be possible to take the path to this file and set it as a variable for use in a DIFFERENT batch file, i have setx in system32 to set a new environment variable if i can get the filepath to be set from there..

    anyone needs any more information please ask but any help would be appreciated.
  2. gbhall

    gbhall TechSpot Chancellor Posts: 2,423   +77

    Probably need to full description of what you want to do - maybe a batch file is not the best answer.

    For simple example, you could try a batch file containing the command

    DIR C:\%1 /s > pathout.txt

    Then %1 is a variable, so you would use the batch file as : findfile name_of_a_file where you substitue the name of the file you are searching for each time you use the batch file. The DIR command lists all the files of that name (and wild card could be used just as easily), with the /S switch causing a recursive search through subdirectories, starting at C:\ The redirection parameter causes the ourput of the DIR command to be output to a text file called pathout.txt.

    If you examine pathout.txt it contains a set of paths and files found in the format

    Directory of C:\mydocu~1\personal

    PERSONAL.DOC 36234 28/07/2008 10:59

    where (because this is a surviving Dos program), the pathname is stated in the old Dos 8.3 layout. You see what I mean by 'not the best answer' ? Then the path(s) could be extracted by, for example, a simple basic program which in turn could actually build, or create the actual paths for use in a different batch file.

    There are umpteen freeware programs from the days of yore capable of doing the same thing as DIR in a million different ways, but sticking to just Windows XP, the Dir command works as described, the ATTRIB command (found in c:\windows\system32) can do much the same thing but outputs full path names without surrounding quote signs.

    There may be no reason not to use the straightforward Windows SEARCH process and just copy and past the results into a batch file opened by notepad, but as I say, depends what you want.
  3. lavo140

    lavo140 TS Rookie Topic Starter

    Hi, sorry, for a full description,

    i am trying to create an autoIT script to run windows files and settings automatically at the end of an unattended installation,
    I already have a batch file to identify the drives attatched to the computer and their corresponding letters, i just need a batch which will look for the file IMG00001.DAT or the folder USMT2.UNC (the folders for the files and settings store) and then get the file path and set it as and environment variable,
    then lauching the autoIT script i can input this variable into the files and settings wizard to keep it fully automated, else id have to get autoIT to ask for a user input of the filepath, to then continue the script.

    Hope this information helps
Topic Status:
Not open for further replies.

Similar Topics

Add New Comment

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