It changes local directory to each of the sub folders found (CD %%D). Next is to walk trough all folders "%D" using the FOR command in the current folder and all sub folders. ![]() Then it stores the current folder in topLevel variable. It first disables echoing (remove OFF if you want to read what actually happens). I took me a while to fiddle it out, but now it works: OFFįOR %%F IN (*) DO IF %%~zF EQU 0 DEL "%%F"įOR /F "usebackq delims=" %%D IN (`"DIR/AD/B/S|SORT/R"`) DO RD "%%D" I've managed to make a macro that can actually delete empty files and empty folders within a folder hierarchy. >nul findstr "^" "yourFileName" || del "yourFileName" So simply delete the file if FINDSTR fails to match a line. But an empty file doesn't have any lines. A FINDSTR search string of "^" will match all lines of a file. However, CALL is slower than FOR (probably not significant in your case) off If you don't want to use a FOR loop, you can use a CALL parameter instead - it uses the same modifiers as FOR variables. If you are going to use this in a batch file than you need to double all the percents ( %%F, %%~zF) for %F in ("yourFileName") do if %~zF equ 0 del "%F" So just substitute your file name for the * wild card. ![]() You want to delete a specific file if it is zero length. It is much simpler to simply use: for %F in (*) do if %~zF equ 0 del "%F" That is more complicated and not as efficient as it could be. The link you cited used the following to delete all 0 length files for /F "delims=" "%I" in ('dir /B') do if not exist "%I\" if %~zI EQU 0 del "%I"
0 Comments
Leave a Reply. |