1.

Solve : Delete zero size files in a drive eg:D:\ in win xp?

Answer»

HelloI use XP SP3 too and ('dir /b /s /a-d') worked fine. I don't know why it didn't work for you. One thing - if you scan a whole drive there may be a long time when NOTHING seems to be happening.

zerodel.bat

Code: [Select]@echo off
setlocal enabledelayedexpansion
set /a file=0
if exist "%temp%\deletions.bat" del "%temp%\deletions.bat"
for /f "delims==" %%A in ('dir /a /b /s /a-d') do (
if "%%~zA"=="0" (
set /a file+=1
echo [!file!] 0 bytes "%%~dpnxA"
echo del "%%~dpnxA" >>"%temp%\deletions.bat"
)
)
Echo.
Echo Deletions:
type %temp%\deletions.bat

output

Code: [Select]C:\basic>zerodel
[1] 0 bytes "C:\basic\freebasic\New Text Document.txt"
[2] 0 bytes "C:\basic\freebasic\examples\compiler.log"
[3] 0 bytes "C:\basic\freebasic\examples\file\.txt"
[4] 0 bytes "C:\basic\freebasic\examples\Windows\COM\MoviePlayer\movctrl\obj\deleteme.txt"
[5] 0 bytes "C:\basic\freebasic\examples\Windows\COM\WebBrowser\webctrl\obj\deleteme.txt"
[6] 0 bytes "C:\basic\freebasic\FbEdit\Projects\Applications\Convert\Convert.bi"
[7] 0 bytes "C:\basic\freebasic\FbEdit\Projects\Samples\DialogApp\DialogApp.Bi"
[8] 0 bytes "C:\basic\freebasic\fbmat020\fbmat020\demo\largeint\PrimFlgs.bin"
[9] 0 bytes "C:\basic\freebasic\mike\projects\colorbars\compiler.log"
[10] 0 bytes "C:\basic\freebasic\mike\projects\graf2\compiler.log"
[11] 0 bytes "C:\basic\freebasic\mike\projects\pi-app\PrimFlgs.bin"
[12] 0 bytes "C:\basic\qbasic\avi.asm"
[13] 0 bytes "C:\basic\qbasic\ETHEREAL.LOG"
[14] 0 bytes "C:\basic\qbasic\RTSP.TXT"
[15] 0 bytes "C:\basic\qbasic\URLDUMP.TXT"

Deletions:
del "C:\basic\freebasic\New Text Document.txt"
del "C:\basic\freebasic\examples\compiler.log"
del "C:\basic\freebasic\examples\file\.txt"
del "C:\basic\freebasic\examples\Windows\COM\MoviePlayer\movctrl\obj\deleteme.txt"
del "C:\basic\freebasic\examples\Windows\COM\WebBrowser\webctrl\obj\deleteme.txt"
del "C:\basic\freebasic\FbEdit\Projects\Applications\Convert\Convert.bi"
del "C:\basic\freebasic\FbEdit\Projects\Samples\DialogApp\DialogApp.Bi"
del "C:\basic\freebasic\fbmat020\fbmat020\demo\largeint\PrimFlgs.bin"
del "C:\basic\freebasic\mike\projects\colorbars\compiler.log"
del "C:\basic\freebasic\mike\projects\graf2\compiler.log"
del "C:\basic\freebasic\mike\projects\pi-app\PrimFlgs.bin"
del "C:\basic\qbasic\avi.asm"
del "C:\basic\qbasic\ETHEREAL.LOG"
del "C:\basic\qbasic\RTSP.TXT"
del "C:\basic\qbasic\URLDUMP.TXT"

C:\basic>
Quote from: Salmon Trout on November 19, 2009, 01:40:07 PM

I use XP SP3 too and ('dir /b /s /a-d') worked fine. I don't know why it didn't work for you. One thing - if you scan a whole drive there may be a long time when nothing seems to be happening.

zerodel.bat

Code: [Select]@echo off
.....
for /f "delims==" %%A in ('dir /a /b /s /a-d') do (
if "%%~zA"=="0" (
set /a file+=1
echo [!file!] 0 bytes "%%~dpnxA"
echo del "%%~dpnxA" >>"%temp%\deletions.bat"
)
)
.....

The above method delete files one by one. Not that its really a big deal, but a suggestion for a more efficient way, since del can delete multiple files passed to it on the command line, is to concat all the FILENAMES into one string, either by batches (or as many as del can TAKE as input) and then pass it to del. Hello


Discussion

No Comment Found