Search code examples
windowsbatch-filecmddir

Windows CMD delete directory


I'm in D:\User Profiles\ and I need to delete directorys located in

D:\User Profiles\---USERNAME---\UPM_Profile\AppData\Local\Mozilla\Firefox\Profiles\*.default

Now here's the question. How can I do this dynamic ? If I type

dir /ad /b /s D:\User Profiles\*\UPM_Profile\AppData\Local\Mozilla\Firefox\Profiles\*.default

it fails. ---USERNAME--- and *.default needs to be dynamic. Any ideas `?


Solution

  • Something like:

    @echo off
    for /d %%i in ("D:\User Profiles\*") do (
       call :remove_dirs %%i
    )
    goto :eof
    
    :remove_dirs
      echo %1
      for /d %%j in ("%1\UPM_Profile\AppData\Local\Mozilla\Firefox\Profiles") do rmdir %%j
      goto :eof