I have the command below to count all directories that that follow the pattern 20??????
:
\'dir /b \"20??????\" | find /c \"2\"\'
(dir /b "20??????" | find /c "2")>>x.txt
set /p variable=<x.txt
That's all.
Of course, if you don't want the file, just do this afterwards:
del x.txt
EDIT -- How to make the filename unique:
@Mai: use this to create a uniqe file name:
set timestamp=%date:.=%%time::=%
set timestamp=%timestamp:,=%
set timestamp=%timestamp:/=%
set timestamp=%timestamp:-=%
set filename=file%timestamp%.tmp
Add more replacements if the date format of your system culture has other characters inside
set cmd="dir /b "20??????" | find /c "2" "
FOR /F "tokens=*" %%i IN (' %cmd% ') DO SET X=%%i
This is my code:
@echo off
set com=echo HI
::Start Of Code You Need
echo|%com%>>"%temp%\tmp.txt"
for /f "tokens=* delims=" %%x in (%temp%\tmp.txt) do (
set output=%%x
)
del /q %temp%\tmp.txt
::End Of Code You Need
echo This Is The Output:
echo %output%
pause>NUL
It takes the input from com
and outputs from output
Here's a sample:
@echo off
set wildcard=C:\*.*
set count=0
FOR /F %%a in ('DIR /B %wildcard%') do set /A count=count+1
echo %count% files matching %wildcard%
set choice=
set /p choice=Press enter to continue ...
@echo off
REM The command fltmc volumes provides some information about drives
REM I need to extract the drive letter associated to a particular volume name.
REM Here's how:
fltmc volumes | find /i "\Device\HarddiskVolume3" > delme.txt
for /f "tokens=1 delims= " %%i in (delme.txt) DO echo %%i
Del /f delme.txt