Page 1 of 1

Delete file and folder under path with wildcard

Posted: 23 Jul 2023 07:37
by cronoping
Hi all, I have this issue and don't found any solution... (I worked on it all the last week without lucky)
I have a structure like this:
C:\Users\UT45\AppData\Logs\
C:\Users\CR45\AppData\Logs\
C:\Users\UT45\AppData\Logs\
I need to delete all the file and folder under Logs folder, but only for the user which username starts with: UT*
This command works for all the file, but not for the folder:

Code: Select all

for /D %%I in ("C:\Users\UT*") do del /A /F /Q  "%%I\AppData\Logs\*" 2>nul
I hope I can find help here...
Thank you to all, have a nice day!

Re: Delete file and folder under path with wildcard

Posted: 23 Jul 2023 13:53
by cronoping
I found it on powershell command:

Code: Select all

powershell -Command "Remove-Item -Path C:\\Users\UT*\AppData\cancellare_contenuto\* -Recurse"
and works fine from the shell.
Do you know how takes no effect through powershell script?
Thank you!

Re: Delete file and folder under path with wildcard

Posted: 24 Jul 2023 01:52
by Batcher
test-1.bat

Code: Select all

@echo off
for /d %%i in ("C:\Users\UT*") do (
    del /a /f /q  "%%i\AppData\Logs\*"
    for /d %%j in ("%%i\AppData\Logs\*") do (
        rd /s /q "%%j"
    )
)

Re: Delete file and folder under path with wildcard

Posted: 24 Jul 2023 02:53
by cronoping
Hi Batcher,
thank you very much! Works perfectly!
Have a nice day, regards