pacerier Posted September 4, 2006 Posted September 4, 2006 hi may i ask, how do we go about detecting a file with the extension let's say .abc in all folders of c:\ drive? i tried if exist c:\*.abc echo detected however this only checks for the root folder and not the subfolders.
allen2 Posted September 4, 2006 Posted September 4, 2006 Try this: setlocaldir /s /b c:\*.abc >c:\dir.txtset detected=no.nofor /f "delims=;" %%i in (c:\dir.txt) do (set detected=%%i)if "%detected%"=="no.no" goto endecho file detected: %detected%:endendlocal
pacerier Posted September 4, 2006 Author Posted September 4, 2006 (edited) hi thanks a lot, erm mind explaining? cause im a noob thxi know dir /s /b c:\*.abc is to find the file but what does >c:\dir.txt does? Edited September 4, 2006 by pacerier
r3incarnat0r Posted September 4, 2006 Posted September 4, 2006 Redirects text output to the c:\dir.txt file.
jaclaz Posted September 4, 2006 Posted September 4, 2006 (edited) isn't this easier?Dir /B /S %1*%2 | FIND "%2">nulECHO Errorlevel is %ERRORLEVEL%@echo off::Check if a file exists in a given directory ::(and subs) by extension - FFBE.CMD::by Jacopo Lazzari::thanks to Rob van Der Woude for the examples, tutorials and ::info on his page http://www.robvanderwoude.com/::and to Simon Sheppard http://www.ss64.com/::-----------------------------------------------------------::Usage: FFBE.CMD <path> <.ext>:: path must end with \::-----------------------------------------------------------::Example FFBE.CMD Dir /B /S %1*%2 | FIND "%2">nulIf %ERRORLEVEL%==0 Echo At least one file with .ext %2 was found(no need to write to a temp file) jaclaz Edited September 4, 2006 by jaclaz
jaclaz Posted September 5, 2006 Posted September 5, 2006 hi thanks, but can we omit >nul?Yes, sure, the only difference will be that the output of the command will be shown on screen, i.e. a listing of all found files matching *.ext.the >nul redirects the standard output of the command to a "NULL DEVICE" instead of default "CONSOLE".jaclaz
IcemanND Posted September 5, 2006 Posted September 5, 2006 for /f %i in ('dir /a /b /s *.abc') do echo %i
IcemanND Posted September 5, 2006 Posted September 5, 2006 it changes the way tah the set what's in the parenthesies is handled. open a cmd window and type 'for /?' for more details
Andromeda43 Posted September 10, 2006 Posted September 10, 2006 Of course, Windows made that a bit easier with the "search" function.Just do a search for *.ABC for instance. All files that fill the bill will be displayed on your screen for you to see. That sure makes it easy to find files of a type or name.Using a batch file, if you don't save the result to a txt file, is kind of a waste of effort.If you're going to the effort of writing a batch file, at least use it to its fullest possibility.dir C:\*.ABC /s >result.txtwill not only find the filenames for you but list them in a text file that you can read or print at your leisure.For instance, when I ran: dir C:\*.wab /s >wabfiles.txt on my own PC, I got the following listing saved to a file called 'wabfiles.txt' which I could easily read with Wordpad. Volume in drive C is SATAMAINMAX Volume Serial Number is 3D3B-1CDA Directory of c:\Documents and Settings\Randy\My Documents07/21/2006 03:39 PM 333,334 myadbook.WAB 1 File(s) 333,334 bytes Directory of c:\Documents and Settings\Randy\Application Data\Microsoft\Address Book09/10/2006 12:28 AM 453,305 Randy.wab09/10/2006 12:28 AM 265,281 Randy.wab~ 2 File(s) 718,586 bytes Total Files Listed: 3 File(s) 1,051,920 bytes 0 Dir(s) 33,878,114,304 bytes freeGood Luck,Andromeda43 B) PS: My name's NOT Randy.
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