Search code examples
batch-filefile-ioremote-serverpsexec

How can "multiple folders/files" be deleted in ONE PSEXEC COMMAND LINE


I can delete remote folders/files via bat command with psexec (below) but; It takes a little time because of the 9 different folders. Maybe, looping of txt file can be used for different folders.

So how we can delete multiple folders in ONE PSEXEC COMMAND LINE?

Here my working code but it does its job in 9 steps :(

psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\1*.*") do rd /s /q "%%a""
psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\2*.*") do rd /s /q "%%a""
psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\3*.*") do rd /s /q "%%a""
psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\4*.*") do rd /s /q "%%a""
psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\5*.*") do rd /s /q "%%a""
psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\6*.*") do rd /s /q "%%a""
psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\7*.*") do rd /s /q "%%a""
psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\8*.*") do rd /s /q "%%a""
psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\9*.*") do rd /s /q "%%a""
psexec \\%PC% cmd /c "for /d %%a in ("c:\Users\T*.*") do rd /s /q "%%a""

Solution

  • psexec \\%PC% cmd /c "for /l %%n in (1;1;9) do  for /d %%a in ("c:\Users\%%n*.*") do rd /s /q "%%a""