Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

detecting files using bat

Featured Replies

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.


Try this:

setlocal
dir /s /b c:\*.abc >c:\dir.txt
set detected=no.no
for /f "delims=;" %%i in (c:\dir.txt) do (set detected=%%i)
if "%detected%"=="no.no" goto end
echo file detected: %detected%
:end
endlocal

  • Author

hi thanks a lot, erm mind explaining? cause im a noob thx

i know dir /s /b c:\*.abc is to find the file but what does >c:\dir.txt does?

Edited by pacerier

isn't this easier?

Dir /B /S %1*%2 | FIND "%2">nul
ECHO 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">nul
If %ERRORLEVEL%==0 Echo At least one file with .ext %2 was found

(no need to write to a temp file) ;)

jaclaz

Edited by jaclaz

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

it changes the way tah the set what's in the parenthesies is handled.

open a cmd window and type 'for /?' for more details

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.txt

will 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 Documents

07/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 Book

09/10/2006 12:28 AM 453,305 Randy.wab

09/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 free

Good Luck,

Andromeda43 B)

PS: My name's NOT Randy. :rolleyes::whistle:;)

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.