DEFLNG a-z
'Uncommented code by Shannon Larratt
'Contact shannon@bmezine.com
'Compiles under PBCC 2.1
'www.powerbasic.com
'Should run under most/all flavors of Windows
FUNCTION PBMAIN
STDOUT "KILLZERO"
STDOUT "This will create killzero.bat, which will delete all 0-length"
STDOUT "files in the current directory or below."
STDOUT
STDOUT "Generating file list...";
SHELL "cmd /c dir *.* /s > killzero.tmp"
DIM filelist$(1 TO 500000)
numfiles = 0
currentdir$ = ""
OPEN "killzero.tmp" FOR INPUT AS #1
DO UNTIL EOF(1)
LINE INPUT #1, x$
x$ = TRIM$(x$)
IF LEFT$(x$, 12) = "Directory of" THEN
currentdir$ = MID$(x$, 14)
ELSEIF LEN(x$) > 39 THEN
tim$ = MID$(x$, 19, 2)
IF (tim$ = "AM" OR tim$ = "PM") AND MID$(x$, 25, 5) <> "
" THEN
INCR numfiles
IF numfiles >= 500000 THEN
STDOUT "(reached max buffer)...";
EXIT LOOP
END IF
filelist$(numfiles) = currentdir$ & "\" & MID$(x$, 40)
END IF
END IF
LOOP
CLOSE #1
KILL "killzero.tmp"
STDOUT "found " & FORMAT$(numfiles, ",") & " file(s)"
STDOUT "Scanning for length...";
OPEN "killzero.bat" FOR OUTPUT AS #1
killed = 0
FOR r = 1 TO numfiles
OPEN filelist$(r) FOR BINARY SHARED AS #2
IF LOF(2) = 0 THEN
IF RIGHT$(filelist$(r),12) <> "killzero.tmp" AND RIGHT$(filelist$(r),12) <> "killzero.bat" THEN
INCR killed
PRINT #1, "del " & filelist$(r)
END IF
END IF
CLOSE #2
NEXT
CLOSE #1
STDOUT "removing " & FORMAT$(killed, ",") & " file(s)"
STDOUT
IF killed = 0 THEN
STDOUT "Found no files to remove!"
ELSE
STDOUT "Run killzero.bat now to delete files; you may want to double"
STDOUT "check the list first though!"
END IF
STDOUT
END FUNCTION