Announcement

Collapse
No announcement yet.

Deleting a directory structure without deleting the name of the root directory

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Deleting a directory structure without deleting the name of the root directory

    HI

    With the command prompt of Windows 7 SP1, how do I delete a directory structure with their files without deleting the name of the root directory?

    THANKS

    BYE
    balubeto

  • #2
    Re: Deleting a directory structure without deleting the name of the root directory

    i.e. delete everything inside the root directory?

    cd "root directory"
    del * /s /q /f
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Deleting a directory structure without deleting the name of the root directory

      From the "run" or the "search" bar you can try the command below.
      Code:
      cmd /c "set @="C:\test\root directory"&call pushd %@%&&(rmdir /s /q .)&popd"
      From a "batch" or "command prompt" you can also do this,
      Code:
      set @="C:\test\root directory"&call pushd %@%&&(rmdir /s /q .)&popd
      What this basically does is setting the root directory as the current working directory. Then, the rmdir statement recursively is removing files and sub directories. The final step of the rmdir statement will fail because the the root folder itself cannot be deleted because it currently is the active ditectory.
      note, That is why the command ends in an error message. However the result is an empty root folder, no files no subdirectories.

      /Rems
      Last edited by Rems; 9th May 2012, 16:28.

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: Deleting a directory structure without deleting the name of the root directory

        Originally posted by Rems View Post
        From the "run" or the "search" bar you can try the command below.
        Code:
        cmd /c "set @="C:\test\root directory"&call pushd %@%&&(rmdir /s /q .)&popd"
        From a "batch" or "command prompt" you can also do this,
        Code:
        set @="C:\test\root directory"&call pushd %@%&&(rmdir /s /q .)&popd
        What this basically does is setting the root directory as the current working directory. Then, the rmdir statement recursively is removing files and sub directories. The final step of the rmdir statement will fail because the the root folder itself cannot be deleted because it currently is the active ditectory.
        note, That is why the command ends in an error message. However the result is an empty root folder, no files no subdirectories.

        /Rems
        How do I eliminate the error message?

        THANKS

        BYE
        balubeto

        Comment


        • #5
          Re: Deleting a directory structure without deleting the name of the root directory

          Originally posted by balubeto View Post
          How do I eliminate the error message?

          THANKS

          BYE
          http://www.robvanderwoude.com/redirection.php

          Code:
          set @="C:\test\root directory"&call pushd %@%&&(rmdir /s /q .)2>NUL&popd
          /Rems

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment

          Working...
          X