1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Batch RD Command

Discussion in 'Software Development' started by bradjoe96, Dec 18, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. bradjoe96

    bradjoe96 Thread Starter

    Joined:
    Dec 18, 2011
    Messages:
    2
    I'm working a small, personal program made in batch to remove the contents of my Downloads folder. I recently found out that wildcards do not work with RD command so I can't tell the program to remove all of the directories, just the files and the files in the subdirectories. I need a command to delete all of the subdirectories out of the Downloads folder, but still leaving the Downloads folder on there.

    Thanks in advance,



    Brad
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Use a for loop to list all the directories and then use the RD command to delete them.
     
  3. bradjoe96

    bradjoe96 Thread Starter

    Joined:
    Dec 18, 2011
    Messages:
    2
    I'm not sure how you would use a for loop to do this. Example? I can post my current code if needed.
     
  4. Frank4d

    Frank4d Retired Trusted Advisor

    Joined:
    Sep 10, 2006
    Messages:
    9,126
    If I understand correctly that you want a completely empty Downloads folder, this should work:

    rd /s /q c:\Downloads
    md c:\Downloads
     
  5. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Always Always Always post the code you are currently using when asking for help.
     
  6. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    That will work for sure but I know sometimes people don't like doing it that way. So here is what I was thinking with the for loop.
    Code:
    pushd c:\users\USERNAME\downloads
    REM removing files from the main downloads directory
    del /q *
    REM removing directories, sub directories and all files
    for /d %%I in (*) do rd /s /q "%%~I"
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1031843

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice