List all files with size via batch file - windows

Found this working code from this post: HERE
Works awesome for listing folders with size, but what needs to be changed in this script to list only files with size not folders?
Script output example:
folder - 105,4 GB
folder1 - 6,7 GB
folder2 - 15,6 GB
#echo off
setlocal disabledelayedexpansion
set "folder=%~1"
if not defined folder set "folder=%cd%"
for /d %%a in ("%folder%\*") do (
set "size=0"
for /f "tokens=3,5" %%b in ('dir /-c /a /w /s "%%~fa\*" 2^>nul ^| findstr /b /c:" "') do if "%%~c"=="" set "size=%%~b"
setlocal enabledelayedexpansion
call :GetUnit !size! unit
call :ConvertBytes !size! !unit! newsize
echo(%%~nxa - !newsize! !unit!
endlocal
)
endlocal
exit /b
:ConvertBytes bytes unit ret
setlocal
if "%~2" EQU "KB" set val=/1024
if "%~2" EQU "MB" set val=/1024/1024
if "%~2" EQU "GB" set val=/1024/1024/1024
if "%~2" EQU "TB" set val=/1024/1024/1024/1024
> %temp%\tmp.vbs echo wsh.echo FormatNumber(eval(%~1%val%),1)
for /f "delims=" %%a in (
'cscript //nologo %temp%\tmp.vbs'
) do endlocal & set %~3=%%a
del %temp%\tmp.vbs
exit /b
:GetUnit bytes return
set byt=00000000000%1X
set TB=000000000001099511627776X
if %1 LEQ 1024 set "unit=Bytes"
if %1 GTR 1024 set "unit=KB"
if %1 GTR 1048576 set "unit=MB"
if %1 GTR 1073741824 set "unit=GB"
if %byt:~-14% GTR %TB:~-14% set "unit=TB"
endlocal & set %~2=%unit%
exit /b

Next code snippet will list only files (not folders) with size. Append both :GetUnit and :ConvertBytes subroutines unchanged.
ECHO OFF >NUL
SETLOCAL enableextensions disabledelayedexpansion
set "folder=%~1"
if not defined folder set "folder=%cd%"
if not exist "%folder%" set "folder=%cd%"
for /F "delims=" %%a in ('dir /B /S /A:-D "%folder%\"') do (
set "size=%%~za"
setlocal enabledelayedexpansion
call :GetUnit !size! unit
call :ConvertBytes !size! !unit! newsize
echo(%%~a - !size! - !newsize! !unit!
endlocal
)
ENDLOCAL
goto :eof
Echoed both !size! and !newsize! merely for debugging purposes...
Another approach with folder name in a header line:
#ECHO OFF >NUL
SETLOCAL enableextensions disabledelayedexpansion
set "folder=%~1"
if not defined folder set "folder=%cd%"
if not exist "%folder%" set "folder=%cd%"
set "subfolder=%folder%"
Call :listfiles
pushd "%folder%"
rem for /D /R %%G in (*) do (
rem the option `/D /R` is undocumented
for /F "delims=" %%G in ('dir /B /A:D *.* 2^>nul') do (
set "subfolder=%%~G"
Call :listfiles
)
popd
ENDLOCAL
goto :eof
:listfiles
pushd "%subfolder%"
echo(
echo folder %cd%
for /F "delims=" %%a in ('dir /B /A:-D *.* 2^>nul') do (
set "size=%%~za"
setlocal enabledelayedexpansion
call :GetUnit !size! unit
call :ConvertBytes !size! !unit! newsize
echo(%%~nxa - !size! - !newsize! !unit!
endlocal
)
popd
goto :eof

Related

Moving specific number of files into newly created numbered folders

I currently have around 550 files in a folder with the same format (.csv) and same headers (all started with the letters "YL").
I wonder if there is a way to splits these files (50 files at a time) (order doesn't matter) into numbered folders? (ex. 1, 2, 3, 4, 5) And also create a subsequent folder for the leftover files?
I have found this scripts and tried to modify it for 50 files, but it looks like it only created a the first folder (subdir1)
#echo off
set /a counter=1
set /a filesperfolder=50
cd dir\dir_main
:loopstart
set dirname=subdir%counter%
md %dirname%
echo %dirname%
dir /b | findstr /v /i "subdir*"> %temp%\temp.txt && for /l %%l in (1,1,%filesperfolder%) do #for /f "tokens=1,2* delims=:" %%a in ('findstr /n /r "^" %temp%\temp.txt ^| findstr /r "^%%l:"') do #move %%b %dirname%\%%b >nul
set /a counter=%counter%+1
for /f "tokens=*" %%a in ('type %temp%\temp.txt ^| find /c /v ""') do set _filesmoved=%%a
del %temp%\temp.txt
IF %_filesmoved% LSS 50 goto done
goto loopstart
:done
cls
echo All files were moved!!
pause
exit
I disliked the script you found as it was hard to read and used a temp file to keep track of the list of files. (Also, it evidently doesn't work, so there's that.)
#echo off
SET /a cnt=50
SET /a fnum=0
FOR /F "delims=" %%f IN ('dir /b /a-d *.csv') DO (
CALL :moveFile "%%f"
)
GOTO :end
:moveFile
IF "%cnt%" equ "50" CALL :makeDir
move "%~1" "%fnum%\%~1"
SET /a cnt+=1
GOTO :EOF
:makeDir
SET /a fnum+=1
mkdir %fnum%
SET /a cnt=0
GOTO :EOF
:end
Here is another way to do it. We test if there are still files in the directory, if there is, create a new directory and copy 50 files.
#echo off & setlocal enabledelayedexpansion
set fold_cnt=1
:test
set file_cnt=50
dir /a-d YL*.csv | findstr /IRC:"File(s)"
if %errorlevel% equ 0 (
mkdir !fold_cnt!
) else (
goto :eof
)
for %%i in (YL*.csv) do (
if not !file_cnt! equ 0 (
set /a file_cnt-=1
move /Y "%%i" "!fold_cnt!\%%i"
)
)
set /a fold_cnt+=1
goto test

File count and size of each folder

I have the following batch script which gives the size of each folder in a directory. I need help in tweaking this or creating a new script so it gives the file count of each folders as well:
#echo off
setlocal disabledelayedexpansion
set "folder=%~1"
if not defined folder set "folder=%cd%"
for /d %%a in ("%folder%\*") do (
set "size=0"
for /f "tokens=3,5" %%b in ('dir /-c /a /w /s "%%~fa\*" 2^>nul ^| findstr /b /c:" "') do if "%%~c"=="" set "size=%%~b"
setlocal enabledelayedexpansion
echo(%%~nxa # !size!
endlocal
)
endlocal
All the information is already in the output of the inner dir command, you only need to change what to retrieve
#echo off
setlocal disabledelayedexpansion
for %%a in ("%~f1.") do set "folder=%%~fa"
for /d %%f in ("%folder%\*") do (
set /a "size=0", "files=0", "directories=0"
for /f "tokens=1,3,5" %%a in ('
dir /-c /a /w /s "%%~ff\*" 2^>nul ^| findstr /b /c:" "
') do if "%%~c"=="" (
set "files=%%~a"
set "size=%%~b"
) else set /a "directories=%%~a/3"
setlocal enabledelayedexpansion
echo(%%~nxf # !size! bytes : !files! files : !directories! directories
endlocal
)
Add this cmd at the end and it will count files in a given dir
setlocal enableextensions
set count=0
for %%x in ("%folder%\*") do set /a count+=1
echo %count%
endlocal
This is inefficient tho, as you are traversing the whole directory twice.
Ideally, you need to combine the two FOR loops into one, just scan the dir once and add the size to the size counter and do count+=1 for each.
Try something like *added spacing to show what i added
set "folder=%~1"
if not defined folder set "folder=%cd%"
set count=0
for /d %%a in ("%folder%\*") do (
set "size=0"
for /f "tokens=3,5" %%b in ('dir /-c /a /w /s "%%~fa\*" 2^>nul ^| findstr /b /c:" "') do if "%%~c"=="" set "size=%%~b"
set /a count+=1
setlocal enabledelayedexpansion
echo(%%~nxa # !size!
endlocal
)
echo %count%
endlocal

count length of filenames in batch

my problem is I want to count the length of multiple filenames and save this numbers into a file.
My approach is this:
#echo off
for %%i in (*.txt) do (
set Datei=%%~ni
call :strLen Datei strlen
:strLen
setlocal enabledelayedexpansion
:strLen_Loop
if not "!%1:~%len%!"=="" set /A len+=1 & goto :strLen_Loop
(endlocal & set %2=%len%)
echo.%strlen%>> tmp
)
The problem here is it only works for the first filename and after that it is stuck and does not go on to the next filename.
Just for another alternative, findstr can output the offset of each matching line. Using it over the dir output and substracting the offset of the previous line from the current one (and the CRLF at the end of the line), we get the length of the previous line / file name
#echo off
setlocal enableextensions disabledelayedexpansion
set "lastOffset=0"
for /f "tokens=1,* delims=:" %%a in ('(dir /b *.txt ^& echo(^) ^| findstr /o "^"') do (
if %%a gtr 0 (
set /a "size=%%a - lastOffset - 2"
setlocal enabledelayedexpansion
echo(!fileName! !size!
endlocal
)
set "lastOffset=%%a"
set "fileName=%%b"
)
Just for another alternative of a one-line command:
for %# in (*.txt) do #for /F "delims=:" %G in ('(echo "%~f#"^&echo(^)^|findstr /O "^"') do #if %~G NEQ 0 ( <^NUL set /p "dummy=%~f#|%~z#|"&set /a %~G-5&echo()
or the same in a bit more readable form:
for %# in (*.txt) ^
do #for /F "delims=:" %G in ('(echo "%~f#"^&echo(^)^|findstr /O "^"') ^
do #if %~G NEQ 0 ( <^NUL set /p "dummy=%~f#|%~z#|"&set /a %~G-5&echo()
Unfortunately, unlike the cmd shell, set command does not display its result in a batch script. Therefore, we need to set a string length to an environment variable and then echo its value with delayed expansion enabled:
#ECHO OFF >NUL
SETLOCAL EnableExtensions EnableDelayedExpansion
rem file lengths:
rem for %%A in (*.txt) do echo Name:%%A, Length: %%~zA
rem full path lengths:
for %%# in (*.txt) do (
for /F "delims=:" %%G in ('(echo "%%~f#"^&echo(^)^|findstr /O "^"') do (
if %%~G NEQ 0 (
set /a "length=%%~G-5"
rem echo(%%~f#^|%%~z#^|!length!
echo(%%~f#^|!length!
)
)
)
A slightly modified how to do count length of file name.
#echo off
SETLOCAL ENABLEDELAYEDEXPANSION
(
for /f "tokens=*" %%A in ('dir *.txt /B /S /A:-D ^| findstr /IV "_output.txt"') do (
set "name=%%~nA"
#echo "!name!">"%TMP%\_Temp.txt"
for %%I in ("%TMP%\_Temp.txt") do (
set /a "length=%%~zI"
set /a length-=4
#echo !length!:'!name!'
)
)
)> _output.txt 2>&1
del "%TMP%\_Temp.txt"
MORE /C /P _output.txt
ENDLOCAL
EXIT /B 0
well the solution was coming from you i just moved the parts out of the loop. the code is this:
#echo off
for %%i in (*.txt) do (
set Datei=%%~ni
call :strLen Datei strlen
)
:strLen
setlocal enabledelayedexpansion
:strLen_Loop
if not "!%1:~%len%!"=="" set /A len+=1
goto :strLen_Loop
(endlocal & set %2=%len%)
echo.%strlen%>> tmp

The process cannot access the file because it is being used by another process.(Batch file)

Device1.bat
#echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
SET FILE=config.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
:end
Device2.bat
#echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
SET FILE=config.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
:end
I am running device1.bat and device2.bat at a time. Device1.bat is running properly.But device2.bat throwing The process cannot access the file because it is being used by another process.please help me to solve this problem.
You could make a temporary copy of the config.properties for the device2 to use and delete it later.
DEVICE 1:
#echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
SET FILE=config.properties
::make a temporary copy of config.properties
copy config.properties config2.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
:end
DEVICE2.bat:
#echo off
:: script for updating property files
SETLOCAL EnableExtensions
SETLOCAL EnableDelayedExpansion
if "%3"=="" (
ECHO Script will optionally accept 3 args: PropKey PropVal File
SET PROPKEY=Deviceid
SET PROPVAL=dfs2341f
::changed config.properties to config2.properties
SET FILE=config2.properties
) ELSE (
SET PROPKEY=%1
SET PROPVAL=%2
SET FILE=%3
)
FINDSTR /B %PROPKEY% %FILE% >nul
IF %ERRORLEVEL% EQU 1 GOTO nowork
MOVE /Y "%FILE%" "%FILE%.bak"
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE "%FILE%.bak" ^|FIND /N /I "%PROPKEY%"`) DO (
SET LINE=%%A
)
FOR /F "tokens=1,2* delims=]" %%S in ("%LINE%") DO SET LINE=%%S
SET /A LINE=%LINE:~1,6%
SET /A COUNT=1
FOR /F "USEBACKQ tokens=*" %%A IN (`FIND /V "" ^<"%FILE%.bak"`) DO (
IF "!COUNT!" NEQ "%LINE%" (
ECHO %%A>>"%FILE%"
) ELSE (
ECHO %PROPKEY%=%PROPVAL%>>"%FILE%"
ECHO Updated %FILE% with value %PROPKEY%=%PROPVAL%
)
SET /A COUNT+=1
)
GOTO end
:nowork
echo Didn't find matching string %PROPKEY% in %FILE%. No work to do.
pause
::delete the temporary config2.properties
del /f /q config2.properties
:end
hope that helps!

cmd and exclamation marks

the following code fails for folder names containing exclamation marks. I think I need DelayedExpansion enabled to handle the nested for loops. Any ideas to get this work? Thanks!
#echo off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set "dest=%~dpn1"
IF "%1" equ "" Set "dest=%cd%"
set /a Folders=0
set /a FoldersWithSubFoldersAndFiles=0
set /a FoldersWithOnlyFiles=0
set /a FoldersWithOnlySubFolders=0
set /a FoldersEmpty=0
for /f "usebackq tokens=*" %%a in (`DIR /AD /S /B "%dest%"`) do (
Set /a Folders+=1
for /f "usebackq tokens=*" %%i in (`DIR "%%a" /A-D /B 2^>NUL^| FIND /C /V ""`) do (
Set NumberOfFiles=%%i
)
for /f "usebackq tokens=*" %%i in (`DIR "%%a" /AD /B 2^>NUL^| FIND /C /V ""`) do (
set NumberOfFolders=%%i
)
IF "!NumberOfFiles!" neq "0" IF "!NumberOfFolders!" neq "0" set /a FoldersWithSubFoldersAndFiles+=1
IF "!NumberOfFiles!" neq "0" IF "!NumberOfFolders!" equ "0" set /a FoldersWithOnlyFiles+=1
IF "!NumberOfFiles!" equ "0" IF "!NumberOfFolders!" neq "0" set /a FoldersWithOnlySubFolders+=1
IF "!NumberOfFiles!" equ "0" IF "!NumberOfFolders!" equ "0" (
set /a FoldersEmpty+=1
echo %%a is empty.
)
)
echo Found %Folders% folders below "%dest%".
echo %FoldersWithSubFoldersAndFiles% folders containing files and subfolders.
echo %FoldersWithOnlyFiles% folders containing files only.
echo %FoldersWithOnlySubFolders% folders containing subfolders only.
echo %FoldersEmpty% folders are empty.
endlocal
I see 3 simple solutions:
1) The slowest method is to use CALL so that you do not need delayed expansion within your loop.
#echo off & setlocal disableDelayedExpansion
set "dest=%~dpn1"
IF "%1" equ "" Set "dest=%cd%"
set /a Folders=0
set /a FoldersWithSubFoldersAndFiles=0
set /a FoldersWithOnlyFiles=0
set /a FoldersWithOnlySubFolders=0
set /a FoldersEmpty=0
for /f "usebackq tokens=*" %%a in (`DIR /AD /S /B "%dest%"`) do (
Set /a Folders+=1
for /f "usebackq tokens=*" %%i in (`DIR "%%a" /A-D /B 2^>NUL^| FIND /C /V ""`) do (
Set NumberOfFiles=%%i
)
for /f "usebackq tokens=*" %%i in (`DIR "%%a" /AD /B 2^>NUL^| FIND /C /V ""`) do (
set NumberOfFolders=%%i
)
call :incrementCounts
)
echo Found %Folders% folders below "%dest%".
echo %FoldersWithSubFoldersAndFiles% folders containing files and subfolders.
echo %FoldersWithOnlyFiles% folders containing files only.
echo %FoldersWithOnlySubFolders% folders containing subfolders only.
echo %FoldersEmpty% folders are empty.
echo See dircount.log for list of empty folders.
endlocal
exit /b
:incrementCounts
IF "%NumberOfFiles%" neq "0" IF "%NumberOfFolders%" neq "0" set /a FoldersWithSubFoldersAndFiles+=1
IF "%NumberOfFiles%" neq "0" IF "%NumberOfFolders%" equ "0" set /a FoldersWithOnlyFiles+=1
IF "%NumberOfFiles%" equ "0" IF "%NumberOfFolders%" neq "0" set /a FoldersWithOnlySubFolders+=1
IF "%NumberOfFiles%" equ "0" IF "%NumberOfFolders%" equ "0" (
set /a FoldersEmpty+=1
echo %%a is empty.
)
exit /b
2) A faster method is to temporarily enable delayed expansion only long enough to transfer the values to FOR variables.
#echo off & setlocal disableDelayedExpansion
set "dest=%~dpn1"
IF "%1" equ "" Set "dest=%cd%"
set /a Folders=0
set /a FoldersWithSubFoldersAndFiles=0
set /a FoldersWithOnlyFiles=0
set /a FoldersWithOnlySubFolders=0
set /a FoldersEmpty=0
for /f "usebackq tokens=*" %%a in (`DIR /AD /S /B "%dest%"`) do (
Set /a Folders+=1
for /f "usebackq tokens=*" %%i in (`DIR "%%a" /A-D /B 2^>NUL^| FIND /C /V ""`) do (
Set NumberOfFiles=%%i
)
for /f "usebackq tokens=*" %%i in (`DIR "%%a" /AD /B 2^>NUL^| FIND /C /V ""`) do (
set NumberOfFolders=%%i
)
setlocal enableDelayedExpansion
for /f "tokens=1,2" %%N in ("!NumberOfFiles! !NumberOfFolders!") do (
endlocal
IF "%%N" neq "0" IF "%%M" neq "0" set /a FoldersWithSubFoldersAndFiles+=1
IF "%%N" neq "0" IF "%%M" equ "0" set /a FoldersWithOnlyFiles+=1
IF "%%N" equ "0" IF "%%M" neq "0" set /a FoldersWithOnlySubFolders+=1
IF "%%N" equ "0" IF "%%M" equ "0" (
set /a FoldersEmpty+=1
echo %%a is empty.
)
)
)
echo Found %Folders% folders below "%dest%".
echo %FoldersWithSubFoldersAndFiles% folders containing files and subfolders.
echo %FoldersWithOnlyFiles% folders containing files only.
echo %FoldersWithOnlySubFolders% folders containing subfolders only.
echo %FoldersEmpty% folders are empty.
echo See dircount.log for list of empty folders.
endlocal
3) But the way I would handle it is to eliminate the 2 variables that are only used within the loop. They aren't used outside the loop, and they are already derived from FOR variables. Since everything is now a FOR variable, you no longer need delayed expansion.
#echo off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set "dest=%~dpn1"
IF "%1" equ "" Set "dest=%cd%"
set /a Folders=0
set /a FoldersWithSubFoldersAndFiles=0
set /a FoldersWithOnlyFiles=0
set /a FoldersWithOnlySubFolders=0
set /a FoldersEmpty=0
for /f "usebackq tokens=*" %%a in (`DIR /AD /S /B "%dest%"`) do (
Set /a Folders+=1
for /f "usebackq tokens=*" %%N in (`DIR "%%a" /A-D /B 2^>NUL^| FIND /C /V ""`) do (
for /f "usebackq tokens=*" %%M in (`DIR "%%a" /AD /B 2^>NUL^| FIND /C /V ""`) do (
IF "%%N" neq "0" IF "%%M" neq "0" set /a FoldersWithSubFoldersAndFiles+=1
IF "%%N" neq "0" IF "%%M" equ "0" set /a FoldersWithOnlyFiles+=1
IF "%%N" equ "0" IF "%%M" neq "0" set /a FoldersWithOnlySubFolders+=1
IF "%%N" equ "0" IF "%%M" equ "0" (
set /a FoldersEmpty+=1
echo %%a is empty.
)
)
)
)
echo Found %Folders% folders below "%dest%".
echo %FoldersWithSubFoldersAndFiles% folders containing files and subfolders.
echo %FoldersWithOnlyFiles% folders containing files only.
echo %FoldersWithOnlySubFolders% folders containing subfolders only.
echo %FoldersEmpty% folders are empty.
echo See dircount.log for list of empty folders.
endlocal

Resources