Batch script question


  1. Posts : 222
    Windows 10
       #1

    Batch script question


    Hello,

    I want make a batch script to delete a spefic folder on the C disk, but how can I get only that spefic folder? I got this:
    Code:
    FOR /D %%p IN ("C:\USERS\%USERNAME%\Downloads\*.*") DO rmdir "%%p" /s /q
    cd C:\USERS\%USERNAME%\Downloads\
    del *.* /q /s
    timeout /t 5 >nul 2>&1 /nobreak
    cls
    It works currently for the Downloads folder, but how can I change that? :)
      My Computer


  2. Posts : 222
    Windows 10
    Thread Starter
       #2

    UP.
      My Computer


  3. Posts : 5,171
    Windows 11 Home
       #3

    That script looks so complicated, I prefer simple ones like:

    Code:
    rmdir "%USERPROFILE%\Downloads" /s /q
    mkdir %USERPROFILE%\Downloads
      My Computer


  4. Posts : 222
    Windows 10
    Thread Starter
       #4

    And how would that work for the C:\ folder?
      My Computer


  5. Posts : 5,171
    Windows 11 Home
       #5

    %USERPROFILE% will choose the current user profile wherever it is located.

    If you want to specify a system disk, you can use %SystemDrive%

    A random folder would be:

    rd ""C:\AMD"" /s /q

    rd ""%SystemDrive%\AMD"" /s /q
      My Computer


  6. Posts : 222
    Windows 10
    Thread Starter
       #6

    Code:
    FOR /D %%p IN (%SystemDrive%\Windows.old) DO rmdir "%%p" /s /q
    cd %SystemDrive%\Windows.old
    del *.* /q /s
    timeout /t 5 >nul 2>&1 /nobreak
    cls
    That?
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 11:46.
Find Us




Windows 10 Forums