Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Jul 2012
    Location
    Kathmandu, Nepal
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Locating “Temporary Internet Files” folder's location and delete with bat

    Basically I need to delete all the temporary files and I've got the following script for it. As all the locations are hard coded and not all people use the default location, I was wondering if anyone could help me with script which would be compatible with the current script that would detect all the "Temporary Internet Files" folder's locations from every profiles present and delete the unwanted. The solution would be a great help.
    Code:
      
    cls
      SET SRC1=%SYSTEMDRIVE%\Documents and Settings
      SET SRC2=Local Settings\Temporary Internet Files
      SET SRC3=Local Settings\Temp
      SET SRC4=Local Settings\History
      SET SRC5=%SYSTEMROOT%\Temp
      SET SRC6=Cookies
    
    
      echo About to delete files from Internet Explorer "Temporary Internet files"
      FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
      echo About to delete files from "Local settings\temp"
      FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR  /S /Q "%%Y"
      FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
      echo About to delete files from "Windows\Temp"
      cd\      
      %systemdrive%
      cd /d %SystemRoot%\temp
      del /F /Q *.*
      @echo Y|RD /S ""
      @echo.
      @echo.
      echo About to delete files from "Local Settings\History"
      FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
    
      FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\today*.*") DO DEL /F /S /Q "%%Y"
    
      FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
    
      echo About to delete files from "%SYSTEMROOT%\Temp"
      FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"
    
      echo About to delete files from "Cookies"
      FOR /D %%X IN ("%SRC1%\*") DO FOR  %%Y IN ("%%X\%SRC6%\*.*") DO DEL /F /S /Q "%%Y"
    
      @echo            Please review any errors if they exist
      @echo.
      @echo.
    Thank you very much in advance

  2. #2
    Plutonium Lounger Medico's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    12,631
    Thanks
    161
    Thanked 936 Times in 856 Posts
    I used a batch file for this chore:


    Start Batch File Below:

    @Echo off
    cls
    Rem: Count the number of files on "C" before the cleanup.
    Echo: Performing initial file count. Please wait!

    for /f "delims=" %%A in ( ' dir /a /s "C:\" ^| find /c /v "" ' ) do set Count1=%%A
    :ause This is not part of the command: the software is interpreting this as an emoticon, it's really a colonP
    Echo:
    Disk Cleanup now starting.
    Please Wait!
    @Echo off

    cleanmgr /sageset:99
    del /F /S /Q "C:\temp\*.*" >nul
    del /F /S /Q "%systemroot%\temp\*.*" >nul
    del /F /S /Q "%systemroot%\SYSTEM32\config\systemprofile\Lo cal Settings\Temporary Internet Files\Content.IE5\*.*" >nul
    del /F /S /Q "%systemroot%\Prefetch\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\Default User\Local Settings\Temporary Internet Files\Content.IE5\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\Default User\Local Settings\History\History.IE5\*.*" >nul
    del /F /S /Q "%homepath%\Cookies\*.*" >nul
    del /F /S /Q "%homepath%\recent\*.*" >nul
    del /F /S /Q "%homepath%\Local Settings\cookies\*.*" >nul
    del /F /S /Q "%homepath%\userdata\*.*" >nul
    del /F /S /Q "%homepath%\Local Settings\History\*.*" >nul
    del /F /S /Q "%homepath%\Local Settings\Temp\*.*" >nul
    del /F /S /Q "%homepath%\Local Settings\History\Temporary Internet Files\Content.IE5\*.*" >nul
    del /F /S /Q "%homepath%\Local Settings\Temporary Internet Files\Content.IE5\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\NetworkService\Cookies\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\NetworkService\Local Settings\History\History.IE5\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\NetworkService\Local Settings\Temp\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\NetworkService\Local Settings\Temporary Internet Files\Content.IE5\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\LocalService\Local Settings\History\History.IE5\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\LocalService\Local Settings\Temporary Internet Files\Content.IE5\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\LocalService\Local Settings\Temp\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\LocalService\Cookies\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\Administrator\Local Settings\Temp\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\Administrator\Local Settings\History\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\Administrator\Cookies\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\Default User\Local Settings\Temporary Internet Files\Content.IE5\*.*" >nul
    del /F /S /Q "C:\Documents and Settings\%Username%\Local Settings\Temporary Internet Files\Content.IE5\*.*" >nul

    cleanmgr /sagerun:99

    Echo: Disk Cleanup is now complete.

    Rem: Show number of files left on HD after the cleanup.
    Echo: Performing File Count, After Cleaning. Please Wait!

    for /f "delims=" %%A in ( ' dir /a /s "C:\" ^| find /c /v "" ' ) do set Count2=%%A
    set /a deleted=%Count1% - %Count2%
    Echo:
    Echo:
    Echo File Count before cleaning: %Count1% files
    Echo:
    Echo File count after cleaning: %Count2% files
    Echo:
    Echo Files deleted:
    %deleted% files
    pause

    End Batch File Above:

    This batch file also counts the numbers of files deleted. It also runs the Disk Cleanup app on steroids. (The 2 cleanmgr command lines can be removed to stop disk cleanup. Once sageset has been set the first time, the Sageset line can also be removed. Just leave the Sagerun command.

    I am not sure if this will clean all profiles. That might require some other lines.
    Last edited by Medico; 2012-07-04 at 10:52.
    BACKUP...BACKUP...BACKUP
    Have a Great Day! Ted


    Sony Vaio Laptop, 2.53 GHz Duo Core Intel CPU, 8 GB RAM, 320 GB HD
    Win 8 Pro (64 Bit), IE 10 (64 Bit)


    Complete PC Specs: By Speccy

  3. The Following User Says Thank You to Medico For This Useful Post:

    anirajstha (2012-07-04)

  4. #3
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,420
    Thanks
    33
    Thanked 195 Times in 175 Posts
    Whatever happened to "live and let live"?!

    Unless I'm very much mistaken, you'll need to be an Administrator to delete Stuff out of any profile other than your own.

    I just do del /s c:\*.tmp every few weeks...
    BATcher

    Time prevents everything happening all at once...

  5. The Following User Says Thank You to BATcher For This Useful Post:

    anirajstha (2012-07-04)

  6. #4
    New Lounger
    Join Date
    Jul 2012
    Location
    Kathmandu, Nepal
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    @Ted Myers: Thank you very much for replying Ted Myers. You script is really good specially the counting part .. but this script also cleans up all the default locations only. What if some users changes the location of "Temporary Internet Files" from their IE settings. (Eg: C:\temp\Temporary Internet Files\*.*) so what I want the script to do is locate all these kind of none default locations of "Temporary Internet Files" and delete them all from every profiles.

    *****"

    @BATcher: Thank you very much BATcher for replying and thank you for the suggestion as well . Yes I do own administrative privilege for deleting these

  7. #5
    New Lounger
    Join Date
    Jul 2012
    Location
    Kathmandu, Nepal
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by anirajstha View Post
    @Ted Myers: Thank you very much for replying Ted Myers. You script is really good specially the counting part .. but this script also cleans up all the default locations only. What if some users changes the location of "Temporary Internet Files" from their IE settings. (Eg: C:\temp\Temporary Internet Files\*.*) so what I want the script to do is locate all these kind of none default locations of "Temporary Internet Files" and delete them all from every profiles.

    *****"

    @BATcher: Thank you very much BATcher for replying and thank you for the suggestion as well . Yes I do own administrative privilege for deleting these
    One other thing guys I want the script to run non interactively .

  8. #6
    Plutonium Lounger Medico's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    12,631
    Thanks
    161
    Thanked 936 Times in 856 Posts
    You would just change the file paths in the batch file if a user changes the location of the item in question. In my own scenario, all my data is on my Data Drive (D Drive) hence if I needed to include something in this drive I would have to specify the path to the something I wanted o include.

    Batch files are made to be very general, then should be customized to your particular needs.
    BACKUP...BACKUP...BACKUP
    Have a Great Day! Ted


    Sony Vaio Laptop, 2.53 GHz Duo Core Intel CPU, 8 GB RAM, 320 GB HD
    Win 8 Pro (64 Bit), IE 10 (64 Bit)


    Complete PC Specs: By Speccy

  9. #7
    New Lounger
    Join Date
    Jul 2012
    Location
    Kathmandu, Nepal
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Ted Myers View Post
    You would just change the file paths in the batch file if a user changes the location of the item in question. In my own scenario, all my data is on my Data Drive (D Drive) hence if I needed to include something in this drive I would have to specify the path to the something I wanted o include.

    Batch files are made to be very general, then should be customized to your particular needs.
    Very generous of you to answer Ted Myers .. Yes I could hard code the changed locations but the thing is I have to deal with 75+ machines which includes 15+ profiles which is very time consuming .. but I will search for alternative of a few days more else I will have to do the dirty work ..
    BTW hope you had a great holiday yesterday .

    Thank you again
    Best Regards

  10. #8
    Plutonium Lounger Medico's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    12,631
    Thanks
    161
    Thanked 936 Times in 856 Posts
    Yes, I had a grand Holiday, thank you.

    Yes working with so many different PC's, it would be time consuming initially, but afterward would be quite simple to update for changes. Unfortunately providing support for that many PC's with various users can be daunting. Good luck with that.
    BACKUP...BACKUP...BACKUP
    Have a Great Day! Ted


    Sony Vaio Laptop, 2.53 GHz Duo Core Intel CPU, 8 GB RAM, 320 GB HD
    Win 8 Pro (64 Bit), IE 10 (64 Bit)


    Complete PC Specs: By Speccy

  11. #9
    Super Moderator
    Join Date
    Jun 2011
    Location
    New England
    Posts
    4,752
    Thanks
    171
    Thanked 650 Times in 573 Posts
    This script locates the Temporary Internet Files folder and then deletes its contents (but see the section about running on remote machines):

    How Can I Delete the Files in the Temporary Internet Files Folder?

    Bruce

  12. #10
    New Lounger
    Join Date
    Jul 2012
    Location
    Kathmandu, Nepal
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BruceR View Post
    This script locates the Temporary Internet Files folder and then deletes its contents (but see the section about running on remote machines):

    How Can I Delete the Files in the Temporary Internet Files Folder?

    Bruce
    Hi BruceR,
    Thank you very much for replying and for the link but it's all in VB, my requirement is only bat file for now..

    Best Regards..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •