Home / Microsoft / Microsoft DOS / Delete zero size files in a drive eg:D:\ in win xp
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2  All - (Bottom) Print
Author Topic: Delete zero size files in a drive eg:D:\ in win xp  (Read 1576 times)
sezzz
Topic Starter
Starter



Posts: 3


« on: November 15, 2009, 08:45:04 PM »

Hai all,
is any bat file option to get all the file with zero size capacity in each drive in winxp drive so that these zero size files has to delete

please help me.
IP logged
gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« Reply #1 on: November 15, 2009, 09:14:20 PM »

see here for vbscript solution. the other easier method, if you can afford to, is to use GNU find. (see my sig to download).
Code: [Select]
c:\test> gnu_find.exe c:\test -type f -size 0 -delete

Of course, if you want to use a pure cmd.exe solution, use a for loop with dir, then use  %~zI . see for /? for more info. OR search this forum.
IP logged

billrich
Guest
« Reply #2 on: November 19, 2009, 09:07:59 AM »

C:\batch>type empty2.bat
@echo off
Code: [Select]
dir  /x *.*  |  find " 0 "  >  zerotxt.txt

for /f "tokens=5 delims= " %%i in (zerotxt.txt) do ECHO  "%%i"

rem for /f "tokens=5 delims= " %%i in (zerotxt.txt) do del /F  "%%i"

rem remove the rem from above  when satisfied  list is correct
C:\batch>

Warning:  Be very careful with search and delete  from root down:  /s
cd \
dir  /X / s *.*  |  find " 0 "  >  zerotxt.txt
« Last Edit: November 19, 2009, 12:04:08 PM by billrich » IP logged
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,363

Computer: Specs
Experience: Guru
OS: Linux variant

1
« Reply #3 on: November 19, 2009, 09:23:40 AM »

code will find nonzero files

Code: [Select]
S:>echo hello > "0 0 0.txt"

S:\Test>dir  *.*  |  find " 0 "
19/11/2009  16:22                 8 0 0 0.txt

QED
IP logged

billrich
Guest
« Reply #4 on: November 19, 2009, 09:47:59 AM »

code will find nonzero files

Code: [Select]
S:>echo hello > "0 0 0.txt"

S:\Test>dir  *.*  |  find " 0 "
19/11/2009  16:22                 8 0 0 0.txt

QED

QED = "Quite Easily Determined"

Sezzz, the original poster,  requested how to find files with zero bytes and how to delete the files with zero bytes.
IP logged
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,363

Computer: Specs
Experience: Guru
OS: Linux variant

1
« Reply #5 on: November 19, 2009, 10:02:50 AM »

"QED" means "Quod erat demonstrandum" (Which was to be shown). It is usually placed at the end of formal proofs in geometry.

What about filenames with spaces?

IP logged

billrich
Guest
« Reply #6 on: November 19, 2009, 10:33:31 AM »

What about filenames with spaces?


Would "" help?

for /f "tokens=5 delims= " %%i in (zerotxt.txt) do del /F  "%%i"

for /f "tokens=5 delims= " %%i in ("zerotxt.txt") do del /F  "%%i"

IP logged
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,363

Computer: Specs
Experience: Guru
OS: Linux variant

1
« Reply #7 on: November 19, 2009, 10:40:32 AM »

no, because in a DIR listing, your token is the part of the file name from the first space to the second

Code: [Select]
26/07/2009  12:01           278,172 Important archive 1 0 0 3.rar
your output

Code: [Select]
"archive"
IP logged

Salmon Trout
Prodigy



Thanked: 501
Posts: 7,363

Computer: Specs
Experience: Guru
OS: Linux variant

1
« Reply #8 on: November 19, 2009, 11:19:49 AM »

I would rather get the file size directly from the FOR variable %%~zA

IP logged

billrich
Guest
« Reply #9 on: November 19, 2009, 11:31:29 AM »

Hello
« Last Edit: November 21, 2009, 10:42:29 PM by billrich » IP logged
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,363

Computer: Specs
Experience: Guru
OS: Linux variant

1
« Reply #10 on: November 19, 2009, 11:35:00 AM »

Yes indeed. Look forward to seeing your efforts.

IP logged

billrich
Guest
« Reply #11 on: November 19, 2009, 11:41:42 AM »

Hello
« Last Edit: November 21, 2009, 10:41:25 PM by billrich » IP logged
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,363

Computer: Specs
Experience: Guru
OS: Linux variant

1
« Reply #12 on: November 19, 2009, 11:52:20 AM »

I will allow Salmon Trout  the pleasure.

Code: [Select]
for /f "delims==" %%A in ('dir /b /s /a-d') do (
    if "%%~zA"=="0" echo File "%%~dpnxA" is 0 bytes
    )

Quote
Was Geometry  your last Math course?

No, calculus, but I remember QED mainly from geometry



IP logged

billrich
Guest
« Reply #13 on: November 19, 2009, 12:02:47 PM »

Hello
« Last Edit: November 21, 2009, 10:40:20 PM by billrich » IP logged
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,363

Computer: Specs
Experience: Guru
OS: Linux variant

1
« Reply #14 on: November 19, 2009, 12:20:56 PM »

if you use dir /b and %%~zA you don't need to worry about spaces
IP logged

Pages: [1] 2  All - (Top) Print 
Home / Microsoft / Microsoft DOS / Delete zero size files in a drive eg:D:\ in win xp « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.089 seconds with 20 queries.