Hi I'm trying to make a batch file easier as I do a similar task to this quite a few times:
del /f /s /q "C:\ProgramData\Kaspersky Lab\AVP6\Data\Updater\Temporary Files\*.*"
del /f /s /q "C:\ProgramData\Kaspersky Lab\AVP7\Data\Updater\Temporary Files\*.*"
del /f /s /q "C:\ProgramData\Kaspersky Lab\AVP8\Data\Updater\Temporary Files\*.*"
del /f /s /q "C:\ProgramData\Kaspersky Lab\AVP9\Data\Updater\Temporary Files\*.*"
del /f /s /q "C:\ProgramData\Kaspersky Lab\AVP10\Data\Updater\Temporary Files\*.*"
del /f /s /q "C:\ProgramData\Kaspersky Lab\AVP11\Data\Updater\Temporary Files\*.*"
Ideally I'd like to wildcard it like:
del /f /s /q "C:\ProgramData\Kaspersky Lab\*\Data\Updater\Temporary Files\*.*"
So that it would delete all the folders mentioned above.
Anyone know how I can do this?
Referencing all subfolders in a folder
Moderator: DosItHelp
Re: Referencing all subfolders in a folder
FOR /D will help you.
Regards
aGerman
Code: Select all
@echo off &setlocal
pushd "C:\ProgramData\Kaspersky Lab" ||goto :eof
for /d %%a in (AVP*) do (
del /f /s /q "%%a\Data\Updater\Temporary Files\*.*"
)
popd
Regards
aGerman
Re: Referencing all subfolders in a folder
Thanks!
One more question though.
Say the folders weren't all called AVP6, AVP7, AVP8 etc and were just random names. Could I change your code to:
for /d %%a in (*)
One more question though.
Say the folders weren't all called AVP6, AVP7, AVP8 etc and were just random names. Could I change your code to:
for /d %%a in (*)
Re: Referencing all subfolders in a folder
Yes, of course. The asterisk is for each literal expression, so your FOR loop will find each subfolder in the current directory.
You could also write something like that
for /d %%a in (?????) do ...
to find all subfolder names with 5 or less single characters.
For experiments it's harmless to echo the found names, e.g.
Regards
aGerman
You could also write something like that
for /d %%a in (?????) do ...
to find all subfolder names with 5 or less single characters.
For experiments it's harmless to echo the found names, e.g.
Code: Select all
for /d %%a in (?????) do echo %%a
pause
Regards
aGerman
Re: Referencing all subfolders in a folder
Thanks once again