0

I'd like to clear the log folder in my web-application that always has the same path to directory. The only thing that changes is the principal folder name for different websites.

How can I delete the contents of folder logs where folder logs is located at C:\Inetpub\websites\XYZ\Portals\Logs where XYZ is variable for all folders inside the C:\Inetpub\websites directory

Ideally a script could be run on-demand and I could add it to windows scheduler to run on an automated basis.

Any examples would be highly appreciated.

2
  • 1
    Why are there forward slashes in Windows paths, shouldn't it be: "\": C:\Inetpub\websites\XYZ\Portals/Logs Dec 7 '20 at 0:36
  • yes backslashes I used the wrong one, question updated sry
    – UserSN
    Dec 7 '20 at 1:34
0

Could be a one liner like this:

for /f "Delims=" %%a in ('dir /b /ad /s C:\Inetpub\websites ^| find /i "C:\Inetpub\websites\" ^|find /i "\Portals\Logs"') do del /q /s /a /f "%%a"
5
  • Is this CMD or PS?
    – UserSN
    Dec 7 '20 at 1:34
  • %%a was unexpected at this time. in CMD
    – UserSN
    Dec 7 '20 at 1:39
  • Run as batch script if that's what you need otherwise run with %a for for loop variable placeholder if you run from cmd. This is CMD but in batch file format as you tagged your question from what I see. If you want to run from command line, only use one % in the %%a listed variable placeholder as written in this answer so for /f "Delims=" %a in ('dir /b /ad /s C:\Inetpub\websites ^| find /i "C:\Inetpub\websites\" ^|find /i "\Portals\Logs"') do del /q /s /a /f "%a" from cmd but as written if run as a batch. This is not PowerShell. Dec 7 '20 at 2:06
  • @FormerlyPimpJuiceIT Thank you
    – UserSN
    Dec 7 '20 at 2:11
  • 1
    It's batch (.bat), already answerd by someone else... Dec 7 '20 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.