deleting of files from a folder subfolder

January 12, 2011 at 10:49:58
Specs: Windows XP, 1 GB
what i want is to delete some files from particular folder, but those files are under a directory or sub-directory whose name may vary. example I want to delete some files name "sms0987.log" from a directory name abc. but this abc folder is under some folder of folders. Now I want to go through each folder and sub folders and if there is a file called sms0987.log or sms7654.log then delete that file.

Till now I tried with this
for /f "tokens=*" %%j in ('dir /b/s sms_*.log') do del %%j

but this is not working. i know there has to be a better a solution than this, can any one please suggest, i am actually a newbie in batch file programming, so any kind of help would be appreciated.

Thanks in advance


See More: deleting of files from a folder subfolder

Report •


#1
January 12, 2011 at 15:51:30
PUSHD "C:\Parent\Directory"
DEL /s sms*.txt
POPD

Can I put a question here?


Report •

#2
January 12, 2011 at 17:19:52
One liner version:
del /s abc\sms_*.log

How To Ask Questions The Smart Way


Report •

#3
January 12, 2011 at 17:30:54
Guess that works too...

Can I put a question here?


Report •

Related Solutions

#4
January 12, 2011 at 18:15:20
thanks for your replies guys, but it is not working.

I tried both the command but it is not working, I think i have to tell you more details. Firstly there is a "main" folder inside main folder suppose there are 3 more folder A B C and inside this 3 folders there are another folder "ABC" in each. Inside this ABC folder some files name sms4567.log sms8787.log files are there which I want to delete, so that I want to write a batch file in such a way that it will traverse through the entire folder and subfolders of Main and it will delete sms*.log files.

I tried this one too del ./ABC sms*.log.

it is working, but the problem is this batch file I have to copy and paste in each ABC folder. I don't want this, I want only 1 batch file which will delete all sms*.log through out.


Report •

#5
January 12, 2011 at 18:26:22
Hi Matt123 your code is working, but need one more help.

Can you tell me how PUSHD and POPD are workign here, a little knowledge transfer from your side to my side would be great, bye the way thanks guys for you replies.

@ Razor2.3 your code is not working, may be folder selection is not happening I think.

thanks anyways


Report •

#6
January 12, 2011 at 18:59:56
PUSHD and POPD are for changing directories. I only added it in, because I thought this might be part of a larder code. You can alternatively place the batch file in the parent directory and just use:

 DEL /s "sms*.txt"

Can I put a question here?


Report •


Ask Question