1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

delete Folders in a Folder not delete folder

Discussion in 'Windows XP' started by wahlroot, 2004/11/30.

Thread Status:
Not open for further replies.
  1. 2004/11/30
    wahlroot

    wahlroot Inactive Thread Starter

    Joined:
    2002/08/15
    Messages:
    546
    Likes Received:
    1
    I have a batch file to delete temp files but it will not delete folders.
    DEL /s /q c:\ "Documents and Settings "\Username\ "Local Settings "\Temp
    If I use the following it deletes Temp file also. I do not want that.
    rd /s /q c:\ "Documents and Settings "\BillandWezzie\ "Local Settings "\Temp
    I hope there is some other way, because I have other folders that I do not want to lose. I think the above folder will come back when needed, but I am not sure.
     
  2. 2004/11/30
    Newt

    Newt Inactive

    Joined:
    2002/01/07
    Messages:
    10,974
    Likes Received:
    2
    I'm not really sure from reading exactly what you want to delete. Do you want the entire temp folder gone (not a really great idea) or simply all the files within it?

    For instance
    del /s /q c:\temp\*.*
    will get rid of all files but will leave any sub-folders under \temp although they will be emptied of any contents.

    Also, it's probably easier to use a single set of " marks so

    "c:\Documents and Settings\Username\Local Settings\Temp\ "*.*
     
    Newt,
    #2

  3. to hide this advert.

  4. 2004/11/30
    surferdude2

    surferdude2 Inactive

    Joined:
    2004/07/04
    Messages:
    4,009
    Likes Received:
    23
    You can accomplish what you desire by using these two lines of script:

    echo y | rd/s "C:\Documents and Settings\Owner\Local Settings\Temp\"

    md "C:\Documents and Settings\Owner\Local Settings\Temp\ "

    I can personally attest to its efficacy since those lines were copied directly from a portion of a batch file that has served me for years.

    The first line will reveal to any old dos scholar how old my batch file is since there is script now that does the same operation with a single switch as opposed to using the echo y | combo. I left it that way for sentimental reasons. :)

    new line would be:

    rd/s/q "C:\Documents and Settings\Owner\Local Settings\Temp\ "

    but that just doesn't sing does it?:D

    Good luck on the batch file. Post back if any ??
     
    Last edited: 2004/11/30
  5. 2004/12/01
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400
    This is mine, named cleanup.cmd :

    taskkill /f /im explorer.exe
    RD /S/q "%UserProfile%\Local Settings\Temporary Internet Files "
    RD /S/q "%UserProfile%\Cookies "
    RD /S/q "%UserProfile%\Local Settings\History "
    RD /S/q "%UserProfile%\Recent "
    RD /S/q "%UserProfile%\Local Settings\Temp\ "
    MD "%UserProfile%\Local Settings\Temp\ "
    pause
    start explorer.exe


    Taskill & start are used to close out explorer.exe & restart it because these folders cannot be removed while explorer is running. I use the MD to create the Temp dir because windows will not recreate the Temp dir after explorer restarts or at boot when explorer starts and my ftp client uses that dir and it won't create the Temp dir if it doesn't exist. I also use the pause because sometimes certain running processes or services are "using some of the dirs" and they won't delete. For example, when windows help service is started, it hooks into those dirs and I may have forgotten to stop the service. TIF, Cookies, History & Recent will get recreated by windows anytime explorer.exe is restarted or loads at boot.

    Also, using %UserProfile% allows this to run on any xp computer and saves having to type exact user paths, it runs as the current logged in user.
     
    Last edited: 2004/12/01
  6. 2004/12/01
    wahlroot

    wahlroot Inactive Thread Starter

    Joined:
    2002/08/15
    Messages:
    546
    Likes Received:
    1
    Hey Newt. I do not want to delete the Temp Folder, just what is in it. Since the line you noted ( "c:\Documents and Settings\Username\Local Settings\Temp\ "*.*) does delete all files, but leave subfolders empty, I will stick with that. It is easier to use a single set of " marks, so I will do that.
    Hey surferdude2. I will try (rd/s/q "C:\Documents and Settings\Owner\Local Settings\Temp\ ") later, since this seems to delete the Temp Folder, as well as what is in it. I am not sure all Temp Folders would be reinstalled.
    Hey TonyT. Since I have the Batch file start at Bootup, I may not need (taskkill /f /im explorer.exe) and (start explorer.exe). Will try them later. Thanks to everyone.
     
  7. 2004/12/01
    WhitPhil

    WhitPhil Inactive

    Joined:
    2002/01/07
    Messages:
    599
    Likes Received:
    4
    "I am not sure all Temp Folders would be reinstalled. "

    Unless these folders are ones that you have created and need, there are no subdirectories required in the \Temp folder.
    Thus just RD the entire thing, and then MD it back.
     
  8. 2004/12/01
    Newt

    Newt Inactive

    Joined:
    2002/01/07
    Messages:
    10,974
    Likes Received:
    2
    TonyT - very nice and thanks. I've tried a copy and I like it. :)
     
    Newt,
    #7
  9. 2004/12/01
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400
    Cool!.
    I keep it in my root dir with a shortcut to it on my desktop. You can change the default icon too. The red big "delete" symbol is nice for it!
     
Thread Status:
Not open for further replies.

Share This Page

  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.