Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: DOS - search and count files in XP  (Read 3205 times)

0 Members and 1 Guest are viewing this topic.

allen3636

  • Guest
DOS - search and count files in XP
« on: February 06, 2011, 05:56:15 PM »
Hello,

please check my script:

@echo off
set loc=c:\temp\labor
set ext=txt
set /p loc=Please enter the search location (default c:\temp\labor) :
set /p ext=Please enter the search file extension (default txt) :
echo ----------------------------------------------------------------------------
echo The search will now search for the files with the extension you have entered
echo *****Please wait this might take a time ***********************
echo ----------------------------------------------------------------------------
echo The result of the search are :
echo ----------------------------------------------------------------------------

for /f "usebackq delims=;" %%q in (`dir /s /b /ad %loc%`) DO (

            for /f "tokens=*" %%a in ( 'dir /s %%q ^| find /c "%ext%"' ) do (

            echo [D] = %%q [F] = %%a

      )
)
echo ----------------------------------------------------------------------------



pause



Salmon Trout

  • Guest
Re: DOS - search and count files in XP
« Reply #1 on: February 07, 2011, 11:52:09 AM »
You omit the dot at the start of a file extension which means that if the user types in (for example) "txt" the search will pick up and count files like mytxt.doc, matxt.jpg, etc. You could narrow it down by searching for the dot as well but you are still going to pick up myfile.txtjpg.zip etc.

Why not restrict the inner search using a wildcard (no dot before ext here)

for /f "tokens=*" %%a in ( 'dir /s %%q\*.%ext% ^| find /c "."' ) do (


Salmon Trout

  • Guest
Re: DOS - search and count files in XP
« Reply #2 on: February 07, 2011, 01:26:59 PM »
This line will cope with folders having spaces in the name

Code: [Select]
for /f "tokens=*" %%a in ( 'dir /s "%%q\*.%ext%" ^| find /c "."' ) do (