[Batch] Delete a Folder with the Del command

Solved
jmber Posted messages 2067 Registration date   Status Contributor Last intervention   -  
creatyssim Posted messages 24 Registration date   Status Member Last intervention   -
Hello everyone, I have a small problem, to explain: I made a Batch file that "cleans" my Temp and Temporary Internet Files folders before shutting down my computer. But I notice that it "deletes" all the files but not the folders. I added the switches /S and /Q but nothing helps. Can you help??
Thanks in advance
--
@+jmber 
Helping each other is precious...

29 answers

  • 1
  • 2
  1. jpdeclermont Posted messages 1792 Status Member 382
     
    Good evening,

    something like this, for example:

    pushd %1
    del /q *.*
    for /f "Tokens=*" %%G in ('dir /B') do rd /s /q "%%G"
    popd

    ** will delete all files AND folders without deleting the root directory, so first navigate to c:\documents and settings\your account\local settings\temporary internet ...

    **** to test, I’m more used to batch...

    -------------------------------
    WinErr 01B: Illegal error - Windows did not allow you to have this error
    4
  2. sebsauvage Posted messages 33284 Registration date   Status Moderator Last intervention   15 684
     
    so for me, at that precise moment, the processes are closed ...

    IE is integrated into Windows, and Windows is never closed.

    The only solution to delete these folders is to do it outside of Windows, apparently.

    Or else kill the handles with ProcessExplorer, then delete the folders, but well :-/

    If these folders are empty, why bother deleting them?
    1
  3. jmber Posted messages 2067 Registration date   Status Contributor Last intervention   680
     
    Thank you for your responses, but I know that if the folder or file is being used by a process, it’s impossible to delete them. I created a folder myself with nothing in it in temporary... and even then it’s impossible.
    --
    @+jmber
    Mutual aid is precious...
    1
  4. jmber Posted messages 2067 Registration date   Status Contributor Last intervention   680
     
    Thank you for your reply, but please tell me where I should place them, please. Here’s what I did:

    cd c:\DOCUME~1\Berto\LOCALS~1\TEMPOR~1
    del *.* /S/Q
    --
    @+jmber 
    L'entraide est précieuse...
    0
  5. sebsauvage Posted messages 33284 Registration date   Status Moderator Last intervention   15 684
     
    deltree /?

    non ?
    0
  6. jpdeclermont Posted messages 1792 Status Member 382
     
    re-

    good evening seb :)

    deltree will only work under win 98
    under xp this command no longer exists (so it seems!!)
    http://www.hiboox.com/image.php?img=qtv4d-5.jpg

    --> jmber
    after your cd:\......
    you will have something like this :

    cd c:\DOCUME~1\Berto\LOCALS~1\TEMPOR~1
    pushd %1
    del /q *.*
    for /f "Tokens=*" %%G in ('dir /B') do rd /s /q "%%G"
    popd

    -------------------------------
    ... WinErr 01B : Illegal error - Windows did not allow you to have this error
    0
  7. sebsauvage Posted messages 33284 Registration date   Status Moderator Last intervention   15 684
     
    Under XP, del supports the /S option to delete subdirectories :-)

    del /?
    0
  8. jpdeclermont Posted messages 1792 Status Member 382
     
    morning friends hello,

    the support supports the /S option
    well yes, that's what I thought too but:

    I added the /S and /Q switches but nothing works (see original message)

    that’s why .... on the other hand, it makes me brush up a bit on DOS commands, we don’t get to work on batch files every day now ..... :D

    -------------------------------
    ... WinErr 01B: Illegal error - Windows did not allow you to have this error
    0
  9. sebsauvage Posted messages 33284 Registration date   Status Moderator Last intervention   15 684
     
    But I notice that it "deletes" all the files but not the folders

    Maybe simply because there are still programs that have handles open on these folders/files?

    It is impossible to delete a file/folder if an application still has control of it.

    And IE and Windows Explorer are loaded in memory almost constantly, hence the impossibility of deleting these folders.

    You will therefore not be able to delete them, which is normal.
    0
  10. jpdeclermont Posted messages 1792 Status Member 382
     
    re-

    yes yes, I am well aware of the problem ...
    i had read that too:
    "clean" my Temp and Temporary Internet Files folders before shutting down my computer

    so for me, at that precise moment, the processes are closed ...
    personally, I use Ccleaner to clean up but of course it’s still a bit longer than a batch .....

    -------------------------------
    ... WinErr 01B: Illegal error - Windows did not allow you to have this error
    0
  11. jpdeclermont Posted messages 1792 Status Member 382
     
    re-

    Ben I just tried with Explorer .... IE is in use
    I go into \documents & settings\my account\local settings\temporary internet.... and I delete anything I want :)

    -------------------------------
    ... WinErr 01B: Illegal error - Windows did not authorize you to have this error
    0
  12. jmber Posted messages 2067 Registration date   Status Contributor Last intervention   680
     
    Re: me too manually I delete everything but with the batch it leaves the folders because with /S /Q it "deletes" the subdirectories and the files inside the folder but not the folder itself (not Tempo... but the folders inside it)!
    --
    @+jmber
    Mutual aid is precious...
    0
  13. sebsauvage Posted messages 33284 Registration date   Status Moderator Last intervention   15 684
     
    and even like that, it's impossible.

    Use ProcessExplorer to see which application still has a handle on it.
    0
  14. jmber Posted messages 2067 Registration date   Status Contributor Last intervention   680
     
    Thanks Seb, I’ll prepare dinner then I’ll download the program and I’ll tell you what! I’ll be back around 7 PM.
    --
    @+jmber 
    Mutual aid is precious...
    0
  15. jmber Posted messages 2067 Registration date   Status Contributor Last intervention   680
     
    Re: I also use SysInternals, especially PsTools, Pskill in particular, because I’m on XP Home and to close processes there’s nothing better, but that isn’t what I need because as I wrote above, I created a folder in Temporary Internet Files and left it with the original name so a new folder, and with a Batch it doesn’t delete itself. Is that possible?? It’s not a big deal, I can do it manually but it’s for my “knowledge”!!
    --
    @+jmber
    Mutual aid is precious...
    0
  16. sebsauvage Posted messages 33284 Registration date   Status Moderator Last intervention   15 684
     
    I created a folder myself in Temporary Internet Files and left it with the original name, so a new folder, and with a batch file it does not delete itself. Is that possible??

    Sorry, I didn’t quite understand what you did.
    0
  17. jmber Posted messages 2067 Registration date   Status Contributor Last intervention   680
     
    You tell me that I don’t know how to delete folders or files because they are in use by Windows, that I know!!! So what I did is create a new folder in Temporary Internet Files which isn’t used by Windows, you understand ?? And so, even this folder that isn’t used by Windows, I don’t know how to “deleter” with a batch, I even tried the RD or RMDIR command because deltree isn’t recognized under XP!!
    --
    @+jmber 
    Mutual aid is precious...
    0
  18. sebsauvage Posted messages 33284 Registration date   Status Moderator Last intervention   15 684
     
    Weird that.

    I just tried it in my Temporary Internet Files folder:

    mkdir toto
    rmdir toto

    and it works without any problem.
    0
  19. jmber Posted messages 2067 Registration date   Status Contributor Last intervention   680
     
    Yes, this way I also delete it (by naming it), but if you run del *.* /S/Q, it will remove the files inside the folder but the toto folder will remain.
    --
    @+jmber 
    Mutual aid is precious...
    0
  20. jmber Posted messages 2067 Registration date   Status Contributor Last intervention   680
     
    Okay but in the Temporary Internet Files folder there are many folders, so if I have to write rmdir..., rmdir..., I’ll do it manually!!!
    --
    @+jmber
    Help is precious...
    0
    1. creatyssim Posted messages 24 Registration date   Status Member Last intervention  
       
      del [Adresse_Dossier]*.[letypedefichier]

      le typedefichier-> the file type designated for example .txt or .bat or .png ...
      0
  • 1
  • 2