Solved batch file delete file begning with the same name

October 16, 2012 at 11:31:41
Specs: Windows XP
hey every body i was workin on a project and I faced this problem. I have a lot of file stored in a folder and the one's i want to delete begin with the same file name. here is how they are, Rxn1, Rxn96, Rxnbt, Rxnty and stuff. they all begin with the suffix "rxn". so how can I delete this files with batch. I tried del /f /q rxn and looped it but its not working. please help. thank you.

See More: batch file delete file begning with the same name

Report •

✔ Best Answer
October 17, 2012 at 17:49:35
@best:
I think, based on your approach, you might need /D instead of /F, in order to obtain directory names:
for /d %%a in ("%location%\rxn*") do rd /s /q "%%a"

the alternative using the /F approach:
for /f "tokens=*" %%a in ('dir /b /a:d %location%\rxn*') do rd /s /q "%location%\%%a"



#1
October 16, 2012 at 14:16:31
Here you go:
del rxn*
.

Report •

#2
October 17, 2012 at 02:54:43
thank you. I tried that but not working. And they are folders. I figuerd i can use the rmdir comand but still wont work with the astrex after the suffix. Any other way please? Thank u again

Report •

#3
October 17, 2012 at 06:44:03
Here:
@echo off & setlocal enabledelayedexpansion
set location=mylocation
for /f %%j in (%mylocation%\rxn*) do rmdir %%j /s
exit /b

Report •

Related Solutions

#4
October 17, 2012 at 17:49:35
✔ Best Answer
@best:
I think, based on your approach, you might need /D instead of /F, in order to obtain directory names:
for /d %%a in ("%location%\rxn*") do rd /s /q "%%a"

the alternative using the /F approach:
for /f "tokens=*" %%a in ('dir /b /a:d %location%\rxn*') do rd /s /q "%location%\%%a"


Report •

#5
October 18, 2012 at 04:48:11
Correct, i knew i had to replace /f with that. lol, i forgot to edit the post. Must of had it mixed up while trying to fix it.

Report •

Ask Question