| 1. |
Solve : Display only total files and bytes line on dir command? |
|
Answer» I am creating a batch file to backup certain directories. After the copy command, I want to compare the total files and bytes of the original directory to the backup directory to confirm everything worked ok. I have used the dir /s command, but that displays pages of files and folders, making the comparison on one screen impossible. What I want to do is display only the next to last line that shows the total files and bytes. If there were something unique in the "string" for that line, I would be fine There is something unique - its position in the output listing, so we can use a FOR loop to successively assign the line CONTAINING "File(s)" to a variable and when the loop is over the variable holds the final value. Just like dir /s, the code below will appear to do nothing for a while if the tree is a deep one with many files. Code: [Select]@echo off for /f "delims=" %%A in ( ' dir /s "D:\Folder" ^| find "File(s)" ' ) do set total=%%A Echo Total for tree is %total% Developed a bit... Code: [Select]@echo off set folder1="D:\test" set folder2="T:\test" for /f "delims=" %%A in ( ' dir /s %folder1% ^| find "File(s)" ' ) do set total1=%%A for /f "delims=" %%A in ( ' dir /s %folder2% ^| find "File(s)" ' ) do set total2=%%A for /F "tokens=1-4" %%A in ("%total1%") do ( set files1=%%A set bytes1=%%C ) for /F "tokens=1-4" %%A in ("%total2%") do ( set files2=%%A set bytes2=%%C ) Echo Folder: %folder1% Files: %files1% Bytes: %bytes1% Echo Folder: %folder2% Files: %files2% Bytes: %bytes2% if "%files1%"=="%files2%" ( echo Number of files: identical ) else ( echo Number of files: NOT identical ) if "%bytes1%"=="%bytes2%" ( echo SIZE of data: identical ) else ( echo Size of data: NOT identical ) Code: [Select]Folder: "D:\test" Files: 2043 Bytes: 165,993,132 Folder: "T:\test" Files: 2043 Bytes: 165,993,132 Number of files: identical Size of data: identical |
|