Was wondering if someone could help me Make A Batch File

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
anoble1
Posts: 22
Joined: 29 Nov 2012 10:24

Re: Was wondering if someone could help me Make A Batch File

#16 Post by anoble1 » 30 Nov 2012 09:05

Thanks for the last post.

I tried the Windows 7, and it deleted the cookies but would not delete the Temp Folder for some reason. My location is called:

C:\Users\x2asnobl\AppData\Local\Microsoft\Windows\Temporary Internet Files

When I went inside the folder there were 2000 files there. But I used the:


:: Delete Temporary Internet Files [ Two Temp location in windows 7 ]
PUSHD "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files"
For /F "delims=" %%A in ('Dir /B /A:D "*.*"') Do (
ATTRIB -S -H -A "%%A"
RMDIR /S /Q "%%A" 2>nul
ATTRIB +S +H +A "%%A"
)
POPD

PUSHD "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\Low"
For /F "delims=" %%A in ('Dir /B /A:D "*.*"') Do (
ATTRIB -S -H -A "%%A"
RMDIR /S /Q "%%A" 2>nul
ATTRIB +S +H +A "%%A"
)
POPD

jemmoe
Posts: 6
Joined: 30 Nov 2012 11:15

Re: Was wondering if someone could help me Make A Batch File

#17 Post by jemmoe » 30 Nov 2012 11:22

Here is a batch file that I use to clean up / clear out some of the stuff that you were talking about:

@echo off
title PC Cleanup Utility

:menu
cls
echo --------------------------------------------------------------------------------
echo PC Cleanup Utility
echo --------------------------------------------------------------------------------
echo.
echo Select a tool
echo =============
echo.
echo [1] Delete Internet Cookies
echo [2] Delete Temporary Internet Files
echo [3] Disk Cleanup
echo [4] Disk Defragment
echo [5] Exit
echo.
set /p op=Run:
if %op%==1 goto 1
if %op%==2 goto 2
if %op%==3 goto 3
if %op%==4 goto 4
if %op%==5 goto exit
goto error
:1
cls
echo --------------------------------------------------------------------------------
echo Delete Internet Cookies
echo --------------------------------------------------------------------------------
echo.
echo Deleting Cookies...
ping localhost -n 3 >nul
del /f /q "%userprofile%\Cookies\*.*"
cls
echo --------------------------------------------------------------------------------
echo Delete Internet Cookies
echo --------------------------------------------------------------------------------
echo.
echo Cookies deleted.
echo.
echo Press any key to return to the menu. . .
pause >nul
goto menu
:2
cls
echo --------------------------------------------------------------------------------
echo Delete Temporary Internet Files
echo --------------------------------------------------------------------------------
echo.
echo Deleting Temporary Files...
ping localhost -n 3 >nul
del /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*"
cls
echo --------------------------------------------------------------------------------
echo Delete Temporary Internet Files
echo --------------------------------------------------------------------------------
echo.
echo Temporary Internet Files deleted.
echo.
echo Press any key to return to the menu. . .
pause >nul
goto menu
:3
cls
echo --------------------------------------------------------------------------------
echo Disk Cleanup
echo --------------------------------------------------------------------------------
echo.
echo Running Disk Cleanup...
ping localhost -n 3 >nul
if exist "C:\WINDOWS\temp"del /f /q "C:WINDOWS\temp\*.*"
if exist "C:\WINDOWS\tmp" del /f /q "C:\WINDOWS\tmp\*.*"
if exist "C:\tmp" del /f /q "C:\tmp\*.*"
if exist "C:\temp" del /f /q "C:\temp\*.*"
if exist "%temp%" del /f /q "%temp%\*.*"
if exist "%tmp%" del /f /q "%tmp%\*.*"
if not exist "C:\WINDOWS\Users\*.*" goto skip
if exist "C:\WINDOWS\Users\*.zip" del "C:\WINDOWS\Users\*.zip" /f /q
if exist "C:\WINDOWS\Users\*.exe" del "C:\WINDOWS\Users\*.exe" /f /q
if exist "C:\WINDOWS\Users\*.gif" del "C:\WINDOWS\Users\*.gif" /f /q
if exist "C:\WINDOWS\Users\*.jpg" del "C:\WINDOWS\Users\*.jpg" /f /q
if exist "C:\WINDOWS\Users\*.png" del "C:\WINDOWS\Users\*.png" /f /q
if exist "C:\WINDOWS\Users\*.bmp" del "C:\WINDOWS\Users\*.bmp" /f /q
if exist "C:\WINDOWS\Users\*.avi" del "C:\WINDOWS\Users\*.avi" /f /q
if exist "C:\WINDOWS\Users\*.mpg" del "C:\WINDOWS\Users\*.mpg" /f /q
if exist "C:\WINDOWS\Users\*.mpeg" del "C:\WINDOWS\Users\*.mpeg" /f /q
if exist "C:\WINDOWS\Users\*.ra" del "C:\WINDOWS\Users\*.ra" /f /q
if exist "C:\WINDOWS\Users\*.ram" del "C:\WINDOWS\Users\*.ram"/f /q
if exist "C:\WINDOWS\Users\*.mp3" del "C:\WINDOWS\Users\*.mp3" /f /q
if exist "C:\WINDOWS\Users\*.mov" del "C:\WINDOWS\Users\*.mov" /f /q
if exist "C:\WINDOWS\Users\*.qt" del "C:\WINDOWS\Users\*.qt" /f /q
if exist "C:\WINDOWS\Users\*.asf" del "C:\WINDOWS\Users\*.asf" /f /q
:skip
if not exist C:\WINDOWS\Users\Users\*.* goto skippy /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.zip del C:\WINDOWS\Users\Users\*.zip /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.exe del C:\WINDOWS\Users\Users\*.exe /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.gif del C:\WINDOWS\Users\Users\*.gif /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.jpg del C:\WINDOWS\Users\Users\*.jpg /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.png del C:\WINDOWS\Users\Users\*.png /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.bmp del C:\WINDOWS\Users\Users\*.bmp /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.avi del C:\WINDOWS\Users\Users\*.avi /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.mpg del C:\WINDOWS\Users\Users\*.mpg /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.mpeg del C:\WINDOWS\Users\Users\*.mpeg /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.ra del C:\WINDOWS\Users\Users\*.ra /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.ram del C:\WINDOWS\Users\Users\*.ram /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.mp3 del C:\WINDOWS\Users\Users\*.mp3 /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.asf del C:\WINDOWS\Users\Users\*.asf /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.qt del C:\WINDOWS\Users\Users\*.qt /f /q
if exist C:\WINDOWS\Users\AppData\Temp\*.mov del C:\WINDOWS\Users\Users\*.mov /f /q
:skippy
if exist "C:\WINDOWS\ff*.tmp" del C:\WINDOWS\ff*.tmp /f /q
if exist C:\WINDOWS\ShellIconCache del /f /q "C:\WINDOWS\ShellI~1\*.*"
cls
echo --------------------------------------------------------------------------------
echo Disk Cleanup
echo --------------------------------------------------------------------------------
echo.
echo Disk Cleanup successful!
echo.
pause
goto menu
:4
cls
echo --------------------------------------------------------------------------------
echo Disk Defragment
echo --------------------------------------------------------------------------------
echo.
echo Defragmenting hard disks...
ping localhost -n 3 >nul
defrag -c -v
cls
echo --------------------------------------------------------------------------------
echo Disk Defragment
echo --------------------------------------------------------------------------------
echo.
echo Disk Defrag successful!
echo.
pause
goto menu
:error
cls
echo Command not recognized.
ping localhost -n 4 >nul
goto menu
:exit


echo Thanks for using PC Cleanup Utility
ping 127.0.0.1 >nul
exit

I hope that this helps! Either way it's a nice utility to have.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#18 Post by abc0502 » 30 Nov 2012 11:43

@jemmoe, does it work for windows 7 because i tested the command in your batch and didn't work for me.
@anoble1, I may have found a way but after i made it and run the batch several files from my desktop and icons was deleted even the batch i made.

Are you sure this is what you want, or you want to delete specific files or folders ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Was wondering if someone could help me Make A Batch File

#19 Post by foxidrive » 30 Nov 2012 11:53

jemmoe wrote:Here is a batch file that I use to clean up / clear out some of the stuff that you were talking about:

@echo off
title PC Cleanup Utility



I'm just commenting that the disk cleanup portion is a mess, and in most cases will not do a thing.
In one part it's checking one spot for files and attempting to delete files from another spot, and the first set of files will not exist in a normal system.


This should clean the %temp% folder: (untested)

Code: Select all

if defined temp (
del "%temp%\*.*" /s /q /f 2>nul
for /f "delims=" %%a in ('dir "%temp%" /ad /b ') do rd "%temp%\%%a" /s /q 2>nul
)

jemmoe
Posts: 6
Joined: 30 Nov 2012 11:15

Re: Was wondering if someone could help me Make A Batch File

#20 Post by jemmoe » 30 Nov 2012 11:55

abc0502 wrote:@jemmoe, does it work for windows 7 because i tested the command in your batch and didn't work for me.
@anoble1, I may have found a way but after i made it and run the batch several files from my desktop and icons was deleted even the batch i made.

Are you sure this is what you want, or you want to delete specific files or folders ?


The file bat file works on my computer, which is windows 7...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Was wondering if someone could help me Make A Batch File

#21 Post by foxidrive » 30 Nov 2012 11:59

jemmoe wrote:
abc0502 wrote:@jemmoe, does it work for windows 7 because i tested the command in your batch and didn't work for me.


The file bat file works on my computer, which is windows 7...


It also doesn't recurse through subdirectories in the temp inet files or the cookie folders. It isn't doing what you think it is...

jemmoe
Posts: 6
Joined: 30 Nov 2012 11:15

Re: Was wondering if someone could help me Make A Batch File

#22 Post by jemmoe » 30 Nov 2012 12:01

foxidrive wrote:
jemmoe wrote:
abc0502 wrote:@jemmoe, does it work for windows 7 because i tested the command in your batch and didn't work for me.


The file bat file works on my computer, which is windows 7...


It also doesn't recurse through subdirectories in the temp inet files or the cookie folders. It isn't doing what you think it is...


I see what you are saying. Alright, then maybe I should keep working on it...

jemmoe
Posts: 6
Joined: 30 Nov 2012 11:15

Re: Was wondering if someone could help me Make A Batch File

#23 Post by jemmoe » 30 Nov 2012 12:02

Please understand that I am new to this stuff, and am VERY eager to learn as much as I can possibly retain. (I am fascinated by the things you can do with VBS and Bat files)

I will take all constructive criticism as you can dish out.

anoble1
Posts: 22
Joined: 29 Nov 2012 10:24

Re: Was wondering if someone could help me Make A Batch File

#24 Post by anoble1 » 30 Nov 2012 12:06

abc0502 wrote:@jemmoe, does it work for windows 7 because i tested the command in your batch and didn't work for me.
@anoble1, I may have found a way but after i made it and run the batch several files from my desktop and icons was deleted even the batch i made.

Are you sure this is what you want, or you want to delete specific files or folders ?


I was just wanting to delete everything in the Temp internet files folder, and cookies folder for XP and 7. I just couldn't get it to work on my workstation.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#25 Post by abc0502 » 30 Nov 2012 12:22

Sorry for that there is a mistake in the batch in the command that identify windows 7 I will fix every thing and post it here

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Was wondering if someone could help me Make A Batch File

#26 Post by foxidrive » 30 Nov 2012 12:36

anoble1 wrote:I was just wanting to delete everything in the Temp internet files folder, and cookies folder for XP and 7. I just couldn't get it to work on my workstation.


You need to query the registry for the locations of those folders as they can be moved. If you only want it for your machine then you can hard code the locations in place.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Was wondering if someone could help me Make A Batch File

#27 Post by foxidrive » 30 Nov 2012 12:43

This deletes the temp inet files, in the default location, for the current user on Win8 and probably Win7 too.

@echo off
del "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /s /q /f 2>nul
pause

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#28 Post by abc0502 » 30 Nov 2012 13:39

Sorry but i had enough with windows 7 :evil:
it refuse to work even with Foxidrive code,
This is the previous code for windows XP:

Code: Select all

@Echo Off
:: Check if OS is XP
ver | find "XP" > nul
if %ERRORLEVEL% == 0 (
      :: Delete Temporary Internet Files
      PUSHD "%userprofile%\Local Settings\Temporary Internet Files"
      For /F "delims=" %%A in ('Dir /B /A:D "*.*"') Do (
         ATTRIB -S -H -A "%%A"
         RMDIR /S /Q "%%A" 2>nul
         ATTRIB +S +H +A "%%A"
         )
      POPD
      
      :: Delete Cookies
      Del /F /Q "%userprofile%\Cookies\*.*" 2>nul
   )
:: Deleting Other Folders [ They should be in general in the same location ]
RMDIR /S /Q "%userprofile%\Documentum\UCF" 2>nul
RMDIR /S /Q "C:\Cache\JAVA" 2>nul
pause


This is what should be used to know if this system is windows 7:
ver | find "[Version" > nul
if %ERRORLEVEL% == 0 goto :win_7
instead of the other one

when i remove the attributes -s -h -r from the Temporary Internet Files
i get 4, 5 folders when i go in them they are having other folders but empty and all other files that was there disappeared.
when restore the attributes all files come back again form no where ?? i can delete them by del key normally but can't with batch ?!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Was wondering if someone could help me Make A Batch File

#29 Post by foxidrive » 30 Nov 2012 13:49

abc0502 wrote:Sorry but i had enough with windows 7 :evil:
it refuse to work even with Foxidrive code,

when i remove the attributes -s -h -r from the Temporary Internet Files
i get 4, 5 folders when i go in them they are having other folders but empty and all other files that was there disappeared.
when restore the attributes all files come back again form no where ?? i can delete them by del key normally but can't with batch ?!


Is that what happened on Win 7? It works on Win8 without changing attributes.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Was wondering if someone could help me Make A Batch File

#30 Post by abc0502 » 30 Nov 2012 14:13

foxidrive wrote:
abc0502 wrote:Sorry but i had enough with windows 7 :evil:
it refuse to work even with Foxidrive code,

when i remove the attributes -s -h -r from the Temporary Internet Files
i get 4, 5 folders when i go in them they are having other folders but empty and all other files that was there disappeared.
when restore the attributes all files come back again form no where ?? i can delete them by del key normally but can't with batch ?!


Is that what happened on Win 7? It works on Win8 without changing attributes.

yes, but maybe it is just my windows, i could have done something to the settings.
when i remove those attributes i get files like "Low", "Content.IE5", "-Anti phishing", and another one related to Microsoft office word.
inside them either empty or other folders that is also empty or have a desktop.ini file. and all the 115 file that was there disappeared. and when put the attributes back the 115 come back again, even there properties is strange !
there location point to internet addresses not location on the HDD.

Post Reply