Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delete Empty Files in a directory.

398 views
Skip to first unread message

David S

unread,
Sep 29, 2011, 12:43:52 AM9/29/11
to
I'm trying to delete an empty file in a specific directory.
I want to scan the directory.
If there is an empty file with the extension of zip, txt or jpg
its deleted
call to c++ app
end
if the are no empty files then
end

I consider an empty file to be zero bytes
This is what I have......I know its similiar to my other post, but
different, The other is time this size.
Any help is appreciated. Thank you.
David

@echo off
cd "C:\Users\DS\Downloads"
setlocal
for /f "delims=" %%a in ('dir *.jpg *.zip *.txt /a-d /b')
if "%~z1" == "0" del %file%

CD C:\RIAA\Warning\debug\
IF EXIST "Warning.exe" call Warning.exe ELSE echo "Does not exists"
goto :EOF

I'm gettin incorrect syntax.

foxidrive

unread,
Sep 29, 2011, 1:12:05 AM9/29/11
to
On 29/09/2011 14:43, David S wrote:
> I'm trying to delete an empty file in a specific directory.
> I want to scan the directory.
> If there is an empty file with the extension of zip, txt or jpg
> its deleted
> call to c++ app
> end
> if the are no empty files then
> end
>
> I consider an empty file to be zero bytes
> This is what I have......I know its similiar to my other post, but
> different, The other is time this size.
> Any help is appreciated. Thank you.
> David
>

This is untested:


@echo off
cd /d "C:\Users\DS\Downloads"
setlocal
for /f "delims=" %%a in ('dir *.jpg *.zip *.txt /a-d /b') do (
if %%~za EQU 0 del %file%
)

CD /d C:\RIAA\Warning\debug\
IF EXIST Warning.exe (call Warning.exe) ELSE (echo Does not exist)
goto :EOF



I asked about RIAA because your folder above shows RIAA.


--
Regards,
Mic

foxidrive

unread,
Sep 29, 2011, 1:16:56 AM9/29/11
to
On 29/09/2011 15:12, foxidrive wrote:

> This is untested:

Note this change: %file% was replaced with "%%a"


@echo off
:: version 1.1
cd /d "C:\Users\DS\Downloads"
setlocal
for /f "delims=" %%a in ('dir *.jpg *.zip *.txt /a-d /b') do (
if %%~za EQU 0 del "%%a"

David S

unread,
Sep 29, 2011, 1:48:01 AM9/29/11
to
It looks like it works. I know I have no zero byte files in that
directory. But it still kicked back the warning box. It should have
done nothing. I name my directories, files all kinds of crazy
things. I just looked RIAA up. Never knew about them. Dont really
listen to any new music so I'm kinda under a rock!
David

foxidrive

unread,
Sep 29, 2011, 2:07:55 AM9/29/11
to
Try this. It should only launch warning.exe if %flag% is set to 1




@echo off
:: version 1.2
cd /d "C:\Users\DS\Downloads"
setlocal
set flag=0
for /f "delims=" %%a in ('dir *.jpg *.zip *.txt /a-d /b') do (
if %%~za EQU 0 (
del "%%a"
set flag=1
)
)
if %flag% EQU 1 (
CD /d C:\RIAA\Warning\debug\
IF EXIST Warning.exe (call Warning.exe) ELSE (echo Does not exist)
)
goto :EOF



--
Regards,
Mic

David S

unread,
Sep 29, 2011, 2:22:51 AM9/29/11
to
Yeaaaaa. It works! Thank you so much!
David

billious

unread,
Sep 29, 2011, 3:26:24 AM9/29/11
to

"David S" <boot...@optonline.net> wrote in message
news:5ae4be18-477d-44de...@c1g2000yql.googlegroups.com...
Not surprising

for /f "delims=" %%a in ('dir *.jpg *.zip *.txt /a-d /b') DO
if "%%~za" == "0" del "%%a"

( all as one line )

1/ Missing DO
2/ %%~za to get the size of file %%a, not %~z1
3/ "%%a" not %file% In all probability, FILE is not an assigned variable, so
%file% will be replaced by NOTHING. Even if it did exist AND contained a
valid filename, you would be attempting to delete that file for each
0-length file found. Quotes around %%a not necessary, but advisable to cater
for spaces and other special characters in the filename %%a.

And I'm not sure whether the size reported for a file that is in the process
of being created is zero until it's closed by the generating program...



David S

unread,
Sep 29, 2011, 3:16:11 PM9/29/11
to
On Sep 29, 3:26 am, "billious" <billious_1...@hotmail.com> wrote:
> "David S" <booty...@optonline.net> wrote in message
> of being created is zero until it's closed by the generating program...- Hide quoted text -
>
> - Show quoted text -

Thank you. I tried to thank you before but they said too many post!
I've never been on a post like the other one, lots great suggestions
and hard work! I thank one and all!
David

jcvmfe...@gmail.com

unread,
Dec 16, 2013, 10:59:19 AM12/16/13
to
Hi all, I got this from stackoverflow.. user Joey has the credits, it works for me.


1.Iterate recursively over the files:
for /r %F in (*)



2.Find out zero-length files:
if %~zF==0



3.Delete them:
del "%F"



Putting it all together:
for /r %F in (*) do if %~zF==0 del "%F"


If you need this in a batch file, then you need to double the %:
for /r %%F in (*) do if %%~zF==0 del "%%F"


Note: I was assuming that you meant files of exactly 0 Bytes in length. If with 0 KB you mean anything less than 1000 bytes, then above if needs to read if %~zF LSS 1000 or whatever your threshold is.


0 new messages