Batch file to search and delete file

Compaq / Cq40-154tu
July 29, 2009 at 04:36:00
Specs: Windows XP
Hi,

Could someone help me please? I want to
have a batch file that can search through my
usb flash drive (say drive H:) to see if there is
any file with extension (say .exe) with the size
100 kb in any folder or without folder (any file
with that identity in the whole usb) and delete
them without confirming. May I know how to
write it?


See More: Batch file to search and delete file

Report •


#1
July 29, 2009 at 06:41:37
If you mean 100K OR BIGGER:

=========================
@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=* delims= " %%a in ('dir/b/s/a-d f:\*.exe') do (
if %%~Za geq 100000 (
del %%a
)
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
July 29, 2009 at 23:52:19
Thanks so much M2 for your help.

I mean the files which are with extension .exe in H:drive (my usb flash
drive) and the size is exactly 100 kb.

Will try your advice and let you know the result :-)

Jacky


Report •

#3
July 30, 2009 at 00:40:28
It didn't work. Even with the file size more than 100 kb. I
tested it a few times. Still, it didn't work.

This is how I did it:

I copied this and pasted into a notepad file and save it as
test.bat then run it. Except for a blink of a black dos screen,
nothing else happened. The files are still there.


@echo off & setLocal EnableDELAYedExpansion
for /f "tokens=* delims= " %%a in ('dir/b/s/a-d f:\*.exe') do (
if %%~Za geq 100000 (
del %%a
)
)


I'm really new to the batch file. Please help...


Report •

Related Solutions

#4
July 30, 2009 at 02:20:52
Go to a prompt:

start ? run > cmd

and run the modified bat below:

=======================
@echo off & setLocal EnableDELAYedExpansion
for /f "tokens=* delims= " %%a in ('dir/b/s/a-d f:\*.exe') do (
if %%~Za geq 100000 (
echo del %%a
)
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question