Results 1 to 2 of 2

Thread: Batch File Help

  1. #1
    Junior Member
    Join Date
    Jul 2005
    Posts
    13

    Batch File Help

    Hey,

    I'm new to batch file programming in Windows. So I was writing this little batch file that searches for a file in a folder. What this code does is search if a file exists within the folder. Just like a dir command except it doesnt include subfolders. Is there any way I could modify this to include the subfolders????

    Here's the code:

    @echo off

    if "%1"=="" goto error


    if exist %1\nul goto folder
    :0
    if exist %1 goto file
    :1
    if exist %1.exe goto exe
    :2
    if exist %1.com goto com
    :3
    if exist %1.sys goto sys
    :4
    if exist %1.dll goto dll
    :5
    if exist %1.doc goto doc
    :6
    if exist %1.txt goto txt
    :7
    if exist %1.zip goto zip
    :8
    if exist %1.bmp goto bmp
    :9
    if exist %1.wav goto wav
    :10
    if exist %1.mp3 goto mp3
    :11
    if exist %1.jpg goto jpg
    :12
    if exist %1.gif goto gif
    :13
    if exist %1.bat goto bat

    if not exist %1\nul goto a
    goto exit
    :a
    if not exist %1 goto b
    goto exit
    :b
    if not exist %1.exe goto c
    goto exit
    :c
    if not exist %1.com goto d
    goto exit
    :d
    if not exist %1.sys goto e
    goto exit
    :e
    if not exist %1.dll goto f
    goto exit
    :f
    if not exist %1.doc goto g
    goto exit
    :g
    if not exist %1.txt goto h
    goto exit
    :h
    if not exist %1.zip goto i
    goto exit
    :i
    if not exist %1.bmp goto j
    goto exit
    :j
    if not exist %1.wav goto k
    goto exit
    :k
    if not exist %1.mp3 goto l
    goto exit
    :l
    if not exist %1.jpg goto m
    goto exit
    :m
    if not exist %1.gif goto n
    goto exit
    :n
    if not exist %1.bat echo %1 does not exist
    goto exit

    :folder
    echo The folder %1 exists
    goto 0

    :file
    echo The file %1 exists.
    goto 1

    :exe
    echo %1.exe exists
    goto 2

    :com
    echo %1.com exists
    goto 3

    :sys
    echo %1.sys exists
    goto 4

    :dll
    echo %1.dll exists
    goto 5

    :doc
    echo %1.doc exists
    goto 6

    :txt
    echo %1.txt exists
    goto 7

    :zip
    echo %1.sys exists
    goto 8


    :bmp
    echo %1.bmp exists
    goto 9

    :wav
    echo %1.wav exists
    goto 10

    :mp3
    echo %1.mp3 exists
    goto 11

    :jpg
    echo %1.jpg exists
    goto 12

    :gif
    echo %1.gif exists
    goto 13

    :bat
    echo %1.bat exists
    goto exit

    :error
    echo usage: is filename

    :exit

    -----------------------------------
    So thats the code. If you're new to batch files too, what u gotta do is open a text file, copy the code, and rename the text file with a .bat extension.
    Then you have to use this from the command prompt.

    usage: is file_name

    well thats it
    aye
    To thine ownself be true

  2. #2
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,401
    Have a look at the FOR command.. help for will give you some info..
    Something like FOR %test IN ('DIR /s') DO yourtests might do the trick..
    Oliver's Law:
    Experience is something you don't get until just after you need it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •