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.

Resolved command line to delete folder contents

Discussion in 'Windows 7' started by Sebastian42, 2012/08/05.

  1. 2012/08/05
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    What line in a batch file would delete the contents of
    C:\Users\MyName\AppData\Local\Microsoft\Windows\Temporary Internet Files\ ?
    del /F /S /Q /A "C:\Users\MyName\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" fails
    so does
    del "C:\Users\MyName\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /q
     
  2. 2012/08/05
    Arie

    Arie Administrator Administrator Staff

    Joined:
    2001/12/27
    Messages:
    15,174
    Likes Received:
    412
    Instead use rd /S "%LOCALAPPDATA%\Microsoft\Windows\Temporary Internet Files "

    You can add the /Q switch for quiet mode.
     
    Arie,
    #2

  3. to hide this advert.

  4. 2012/08/05
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    NO improvement
     
  5. 2012/08/05
    SpywareDr

    SpywareDr SuperGeek WindowsBBS Team Member

    Joined:
    2005/12/31
    Messages:
    3,752
    Likes Received:
    338
  6. 2012/08/15
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    To solve a problem in Window Live Mail, I was advised to empty the Temporary Internet Files folder. I found that it is an easy matter to select all its contents and dispose of them by pressing the delete key. It seems sensible maintenance, so I tried to automate the process by writing a batch file. However the code I used will not work for THAT folder (TIF)- it will empty other folders. I would like code for a batch file (command line) that automates what I CAN do manually. I have established that the 'delete Temporary Internet Files' setting of CCleaner ALSO fails to do what I can achieve manually; and the 'delete' button of Internet Options likewise fails.
     
  7. 2012/08/15
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    SpywareDR - your suggestion looked like it had possibilities, so even though I understand very little of it, I ran the following code :


    @echo off

    SET SRC1=C:\Documents and Settings
    SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
    SET SRC3=Local Settings\History
    SET SRC4=Local Settings\Temp
    SET SRC5=Cookies

    echo cleaning temporary internet files
    FOR /D %%X IN ( "%SRC1%\* ") DO FOR /D %%Y IN ( "%%X\%SRC2%\*.* ") DO RMDIR /S /Q "%%Y "

    echo cleaning history
    FOR /D %%X IN ( "%SRC1%\* ") DO FOR /D %%Y IN ( "%%X\%SRC3%\*.* ") DO RMDIR /S /Q "%%Y "

    echo cleaning windows temp files
    FOR /D %%X IN ( "%SRC1%\* ") DO FOR /D %%Y IN ( "%%X\%SRC4%\*.* ") DO RMDIR /S /Q "%%Y "
    FOR /D %%X IN ( "%SRC1%\* ") DO FOR %%Y IN ( "%%X\%SRC3%\*.* ") DO DEL /F /S /Q "%%Y "
    FOR /D %%X IN ( "%SRC1%\* ") DO FOR %%Y IN ( "%%X\%SRC4%\*.* ") DO DEL /F /S /Q "%%Y "

    echo cleaning Cookies
    FOR /D %%X IN ( "%SRC1%\* ") DO FOR %%Y IN ( "%%X\%SRC5%\*.* ") DO DEL /F /S /Q "%%Y "

    del /f /s /q "%windir%\temp "
    FOR /D %%X IN ( "%windir%\temp\* ") DO RMDIR /S /Q "%%X "

    It made NO difference to the contents of TIF while I watched them but I know that code is meant to operate 'on logoff'.
    "Document and Settings" suggests to me that it is for WinXP, since I have not been able to find a 'documents and settings' in Win7.
     
  8. 2012/08/15
    Steve R Jones

    Steve R Jones SuperGeek Staff

    Joined:
    2001/12/30
    Messages:
    12,285
    Likes Received:
    249
    DEL C:\Folder1\Folder2\*.*
    will delete anything and everything underneath Folder2.
     
  9. 2012/08/15
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,068
    Likes Received:
    396
    You cannot remove the temporary internet files dir (RD) while explorer is running. Same with cookies, history and any other dir that has an index.dat file in it. You'll need to use taskkill explorer.exe prior to removing those dirs.

    This should work:
    Code:
    @echo off
    taskkill /f /im explorer.exe
    rd /S/q  "%LOCALAPPDATA%\Microsoft\Windows\Temporary Internet Files "
    start explorer.exe
    Also, if have Google Chrome installed, and it's updating itself, then deleting the temp internet files will fail.
     
  10. 2012/08/15
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    As I stated, my code works for other folders, but NOT for Temporary Internet Files folder.
     
  11. 2012/08/15
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    I have Chrome installed, but rarely use it. Presumably it wont update unless it is launched.

    I have not tried to remove the TIF folder, but to empty it of contents - I CAN do that 'manually', actually USING Windows Explorer.

    Because that TIF folder is needed, I added the line :

    "md "%LOCALAPPDATA%\Microsoft\Windows\Temporary Internet Files "

    and then watched the contents of TIF as I double-clicked that bat file on the desktop. NO improvement.
    More to the point, the bat file hangs WITHOUT CONTENT in a 'DOS' Window.

    I noticed the term '%LOCALAPPDATA%' and do not really understand it, but the path to the TIF folder contains '\AppData\Local\'. Is THAT discrepancy like to cause the problem ?
     
    Last edited: 2012/08/15
  12. 2012/08/16
    Arie

    Arie Administrator Administrator Staff

    Joined:
    2001/12/27
    Messages:
    15,174
    Likes Received:
    412
    The command posted by Tony works fine. When you run it from within Windows, you'll have to run it with Admin. privileges.

    Copy the .bat file to C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup and it will be run when Windows starts.

    The Temporary Internet Files folder gets re-created once you start IE.
     
  13. 2012/08/16
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,068
    Likes Received:
    396
    No need to use MD because the TIF dir will get recreated automatically next time IE is run.
    %ABCDEFG% = environment variables:
    http://technet.microsoft.com/en-us/library/dd560744(v=ws.10).aspx

    Try using:
    rd /S/q "%CSIDL_INTERNET_CACHE% "
    or the full path:
    rd /S/q " C:\Users\username\AppData\Local\Microsoft\Windows\Temporary Internet Files "

    oops, thanks Arie, I forgot that.
     
  14. 2012/08/16
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    "No need to use MD because the TIF dir will get recreated automatically next time IE is run. "
    Since I rarely use I.E. but TIF is obviously replenished at each booting (?) [and therefore, I infer, NEEDED], I want re-assurance that it comes right without having to launch I.E.
     
  15. 2012/08/16
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    "you'll have to run it with Admin. privileges "
    How would I do that for a batch file ?
     
  16. 2012/08/16
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
  17. 2012/08/16
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    "Copy the .bat file to C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup and it will be run when Windows starts. "

    I KNOW here to put a batch file so that it will run at Windows Launch.
    I did not necessarily want my batch to run at Windows launch. I simply wanted a batch that would work when I run it.
     
  18. 2012/08/16
    Arie

    Arie Administrator Administrator Staff

    Joined:
    2001/12/27
    Messages:
    15,174
    Likes Received:
    412
    Right-click run as administrator
     
  19. 2012/08/16
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    rd /S/q "C:\Users\username\AppData\Local\Microsoft\Windows\Temporary Internet Files "

    Running that code in a batchfile did NOT affect the content of the TIF folder. So I ran it again. Only once did a 'DOS' window show with lots of 'file can't be found' - but not long enough for me to see which files failed. Subsequent runnings simply show a 'DOS' window for an instant. Most importantly - NO improvement for emptying TIF (or deleting it).
     
  20. 2012/08/16
    Sebastian42

    Sebastian42 Well-Known Member Thread Starter

    Joined:
    2008/11/25
    Messages:
    84
    Likes Received:
    0
    Clicking 'run as administrator' in the content menu of the batch file, left TIF and its contents as I found them.
     
  21. 2012/08/16
    Arie

    Arie Administrator Administrator Staff

    Joined:
    2001/12/27
    Messages:
    15,174
    Likes Received:
    412
    Well, it does work perfectly fine for me.

    So.... what folder (full path) are you looking at?
     

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.