We help IT Professionals succeed at work.

Batch File Help - Suppress RD to show progress bar.

So what im trying to do is run these:

cd %SYSTEMDrive%\
RD /s /q "%WINDIR%\Prefetch"
RD /s /q "%TEMP%"
RD /s /q "%USERPROFILE%\Local Settings\Temp"
RD /s /q "%USERPROFILE%\Local Settings\Temporary Internet Files"
RD /s /q "%USERPROFILE%\Cookies"
RD /s /q "%SystemRoot%\Downloaded Program Files"
RD /s /q "%SystemRoot%\Temp"
RD /s /q "%SystemRoot%\tmp"
REM  ---Super File Cleaner
del /f /s /q %SystemDrive%\*.log
del /f /s /q %SystemDrive%\~*.*
del /f /s /q %SystemDrive%\*.tmp
del /f /s /q %SystemDrive%\*.bak
del /f /s /q %SystemDrive%\*.old
REM  ---END of Super File Cleaner
RD /s /q "C:\$Recycle.bin"

Open in new window


But some how display this:

@echo off
setlocal enabledelayedexpansion
echo.
echo.
set i=0
(Set /P j=Now Cleaning your System) < NUL
ECHO.
ECHO.
(Set /P j= ) < NUL

:start
call :show %i%

:put the command in the next line

set /a i = i + 2
if /i %i% leq 100 goto start
ECHO.
ECHO.
(Set /P j=Your System is now Clean) < NUL
ECHO.
PAUSE>NUL
goto :EOF

:show
(Set /P j=Û) < NUL
title %1%% Done
exit /b
endlocal

Open in new window


1) can it be done?
2) is there a better way?

Thank you for your help in advanced.

Any suggestions would be greatly appreciated.
Comment
Watch Question

Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Only approximately, because you get no finer granularity than a single RD or DEL command, so you won't get a good progress bar. The lineecho %%Lshould be replaced by%%Las soon as you are certain the comands should really be executed.
@echo off
setlocal enabledelayedexpansion
echo.
echo.
set i=0
echo Now Cleaning your System
echo.
(Set /P j= ) < NUL

for /F "tokens=1 delims=[]" %%N in ('find /N ":StartOfCode" ^<"%~0"') do set start=%%N
for /F %%N in ('find /C /V "" ^<"%~0"') do set /A lines=%%N-start
set line=0
for /F "skip=%start% usebackq tokens=* delims=" %%L in ("%~0") do (
  REM remove the "echo" below after testing to really execute the command
  echo %%L
  set /P j=ÿ< NUL
  set /A line += 1
  set /A pct= line * 100 / lines
  title !pct!^% done
)  

ECHO.
ECHO.
echo Your System is now Clean

PAUSE>NUL
exit /b


:StartOfCode
cd %SYSTEMDrive%\
RD /s /q "%WINDIR%\Prefetch"
RD /s /q "%TEMP%"
RD /s /q "%USERPROFILE%\Local Settings\Temp"
RD /s /q "%USERPROFILE%\Local Settings\Temporary Internet Files"
RD /s /q "%USERPROFILE%\Cookies"
RD /s /q "%SystemRoot%\Downloaded Program Files"
RD /s /q "%SystemRoot%\Temp"
RD /s /q "%SystemRoot%\tmp"
REM  ---Super File Cleaner
del /f /s /q %SystemDrive%\*.log
del /f /s /q %SystemDrive%\~*.* 
del /f /s /q %SystemDrive%\*.tmp
del /f /s /q %SystemDrive%\*.bak
del /f /s /q %SystemDrive%\*.old
REM  ---END of Super File Cleaner
RD /s /q "C:\$Recycle.bin"

Open in new window

Author

Commented:
That produced a weird output for me...i dont think it "cleaned" anything. In fact i still have a file in my recycling bin.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Yes, the output is intentionally a progress symbol plus the line to execute. Just replace line 15 with
%%L
as I described to really execute the commands.

Author

Commented:
Well thats the thing i DID remove ECHO and it still produced an output but it didn't do anything... like i said.. i still have an item in my recycling bin.. Pretty "h" brackets though...
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
Several strange effects here. Let's try again:
@echo off
setlocal enabledelayedexpansion
echo.
echo.
set i=0
echo Now Cleaning your System
echo.
(Set /P j= ) < NUL

for /F "tokens=1 delims=[]" %%N in ('find /N ":StartOfCode" ^<"%~f0"') do set start=%%N
for /F %%N in ('find /C /V "" ^<"%~f0"') do set /A lines=%%N-start
set line=0
for /F "skip=%start% usebackq tokens=* delims=" %%L in ("%~f0") do (
  call %%L 2>nul >nul
  set /P j=Û< NUL
  set /A line += 1
  set /A pct= line * 100 / lines
  title !pct!^% done
)  

ECHO.
ECHO.
echo Your System is now Clean

PAUSE>NUL
exit /b


:StartOfCode
cd /D %SYSTEMDrive%\
RD /s /q "%WINDIR%\Prefetch"
RD /s /q "%TEMP%"
RD /s /q "%USERPROFILE%\Local Settings\Temp"
RD /s /q "%USERPROFILE%\Local Settings\Temporary Internet Files"
RD /s /q "%USERPROFILE%\Cookies"
RD /s /q "%SystemRoot%\Downloaded Program Files"
RD /s /q "%SystemRoot%\Temp"
RD /s /q "%SystemRoot%\tmp"
REM  ---Super File Cleaner
del /f /s /q %SystemDrive%\*.log
del /f /s /q %SystemDrive%\~*.* 
del /f /s /q %SystemDrive%\*.tmp
del /f /s /q %SystemDrive%\*.bak
del /f /s /q %SystemDrive%\*.old
REM  ---END of Super File Cleaner
RD /s /q "C:\$Recycle.bin"

Open in new window

Author

Commented:
ok wow.. thats doing something now...  but still displaying the visible code and not displaying the bars... is that even possible?
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
That is really strange, and I cannot think of any reason for that. Can you show me a screenshot, or cut&paste the output here?

Author

Commented:
sure:
<code>

C:\Users\XXXXX\Desktop>n++@echo off
'n++@echo' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\XXXXX\Desktop>setlocal enabledelayedexpansion

C:\Users\XXXXX\Desktop>echo.


C:\Users\XXXXX\Desktop>echo.


C:\Users\XXXXX\Desktop>set i=0

C:\Users\XXXXX\Desktop>echo Now Cleaning your System
Now Cleaning your System

C:\Users\XXXXX\Desktop>echo.


C:\Users\XXXXX\Desktop>(Set /P j=  ) 0<NUL

C:\Users\XXXXX\Desktop>for /F "tokens=1 delims=[]" %N in ('find /N ":Star
OfCode" <"C:\Users\XXXXX\Desktop\New Text Document.bat"') do set start=%N


C:\Users\XXXXX\Desktop>set start=10

C:\Users\XXXXX\Desktop>set start=29

C:\Users\XXXXX\Desktop>for /F %N in ('find /C /V "" <"C:\Users\jdibernard
\Desktop\New Text Document.bat"') do set /A lines=%N-start

C:\Users\XXXXX\Desktop>set /A lines=46-start

C:\Users\XXXXX\Desktop>set line=0

C:\Users\XXXXX\Desktop>for /F "skip=29 usebackq tokens=* delims=" %L in (
C:\Users\XXXXX\Desktop\New Text Document.bat") do (
call %L  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\Users\XXXXX\Desktop>(
call cd /D %SYSTEMDrive%\  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call RD /s /q "%WINDIR%\Prefetch"  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call RD /s /q "%TEMP%"  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call RD /s /q "%USERPROFILE%\Local Settings\Temp"  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call RD /s /q "%USERPROFILE%\Local Settings\Temporary Internet Files"  2>nul 1>
ul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call RD /s /q "%USERPROFILE%\Cookies"  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call RD /s /q "%SystemRoot%\Downloaded Program Files"  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call RD /s /q "%SystemRoot%\Temp"  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call RD /s /q "%SystemRoot%\tmp"  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call REM  ---Super File Cleaner  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call del /f /s /q %SystemDrive%\*.log  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call del /f /s /q %SystemDrive%\~*.*   2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call del /f /s /q %SystemDrive%\*.tmp  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call del /f /s /q %SystemDrive%\*.bak  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call del /f /s /q %SystemDrive%\*.old  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call REM  ---END of Super File Cleaner  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>(
call RD /s /q "C:\$Recycle.bin"  2>nul 1>nul
 set /P j=+¢ 0<NUL
 set /A line += 1
 set /A pct= line * 100 / lines
 title !pct! done
)

C:\>ECHO.


C:\>ECHO.


C:\>echo Your System is now Clean
Your System is now Clean

C:\>PAUSE1>NUL
</code>

Author

Commented:
And this is what should output right?



C:\Users\XXXXX\Desktop>echo off


Now Cleaning your System

¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦

Your System is now Clean



Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
You should not even see the @echo off. There are some extranous characters in front of the first line - please store the batch file as ASCII (text-only), not ANSI, UTF-8 or Unicode.

Author

Commented:
Ok how do i set that in windows 7?
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
Correction: Save it as ANSI, not UTF-8 or Unicode. In Notepad you have an option in the bottom line to change the coding.

Author

Commented:
OHH WAIT!! ok for Windows 7 it has to be saved as a ANSI txt/bat file for it to work right...

Your awesome thank you..

Author

Commented:
Qlemo:

Why is it when i paste it into my master bat file it works weird...

It should work like that right?
@color 0A
:MENU
ECHO.
ECHO ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
ECHO º      Choose Your Tool       º
ECHO ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
ECHO.
ECHO 1 - Windows XP (Temp Cleaner)
ECHO 2 - Windows 7 (Temp Cleaner)
ECHO.
SET /P M=Select a number, then press ENTER: 
IF %M%==1 GOTO XP
IF %M%==2 GOTO 7

:XP
CLS
@COLOR 04
@ECHO OFF
setlocal enabledelayedexpansion
@ECHO.
@ECHO.
set i=0
@Echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
@ECHO º       Now Cleaning Your System      º
@Echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
@ECHO.
(Set /P j= ) < NUL

for /F "tokens=1 delims=[]" %%N in ('find /N ":StartOfCodeXP" ^<"%~f0"') do set start=%%N
for /F %%N in ('find /C /V "" ^<"%~f0"') do set /A lines=%%N-start
set line=0
for /F "skip=%start% usebackq tokens=* delims=" %%L in ("%~f0") do (
  call %%L 2>nul >nul
  set /P j=Û< NUL
  set /A line += 1
  set /A pct= line * 100 / lines
  title !pct!^% done
)  

GOTO Done

:StartofCodeXP
cd %SYSTEMDrive%\
RD /s /q "%WINDIR%\Prefetch"
RD /s /q "%TEMP%"
RD /s /q "%USERPROFILE%\Local Settings\Temp"
RD /s /q "%USERPROFILE%\Local Settings\Temporary Internet Files"
RD /s /q "%USERPROFILE%\Cookies"
RD /s /q "%SystemRoot%\Downloaded Program Files"
RD /s /q "%SystemRoot%\Temp"
RD /s /q "%SystemRoot%\tmp"
RD /s /q "C:\$Recycle.bin"
REM  ---Super File Cleaner
del /f /s /q %SystemDrive%\*.log
del /f /s /q %SystemDrive%\~*.*
del /f /s /q %SystemDrive%\*.tmp
del /f /s /q %SystemDrive%\*.bak
del /f /s /q %SystemDrive%\*.old
REM  ---END of Super File Cleaner

:7
CLS
@COLOR 04
@ECHO OFF
setlocal enabledelayedexpansion
@ECHO.
@ECHO.
set i=0
@Echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
@ECHO º       Now Cleaning Your System      º
@Echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
@ECHO.
(Set /P j= ) < NUL

for /F "tokens=1 delims=[]" %%N in ('find /N ":StartOfCode7" ^<"%~f0"') do set start=%%N
for /F %%N in ('find /C /V "" ^<"%~f0"') do set /A lines=%%N-start
set line=0
for /F "skip=%start% usebackq tokens=* delims=" %%L in ("%~f0") do (
  call %%L 2>nul >nul
  set /P j=Û< NUL
  set /A line += 1
  set /A pct= line * 100 / lines
  title !pct!^% done
)  

GOTO Done

:StartOfCode7
cd /D %SYSTEMDrive%\
RD /s /q "%WINDIR%\Prefetch"
RD /s /q "%TEMP%"
RD /s /q "%USERPROFILE%\Local Settings\Temp"
RD /s /q "%USERPROFILE%\Local Settings\Temporary Internet Files"
RD /s /q "%USERPROFILE%\Cookies"
RD /s /q "%SystemRoot%\Downloaded Program Files"
RD /s /q "%SystemRoot%\Temp"
RD /s /q "%SystemRoot%\tmp"
RD /s /q "C:\$Recycle.bin"
REM  ---Super File Cleaner
del /f /s /q %SystemDrive%\*.log
del /f /s /q %SystemDrive%\~*.* 
del /f /s /q %SystemDrive%\*.tmp
del /f /s /q %SystemDrive%\*.bak
del /f /s /q %SystemDrive%\*.old
REM  ---END of Super File Cleaner

:Done
CLS
@COLOR 0A
@Echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
@Echo º      Your System is now Clean       º
@Echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
@PAUSE
CLS
GOTO MENU

Open in new window

Author

Commented:
Add Echo off to that top part too =P
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
No. The FOR loop reading :StartOfCodeXP will read until the EOF, which is too much. To embed that script into another one as you did, we need a little more effort; it hasn't been part of the initial requirement 8-o.

@color 0A
:MENU
ECHO.
ECHO ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
ECHO º      Choose Your Tool       º
ECHO ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
ECHO.
ECHO 1 - Windows XP (Temp Cleaner)
ECHO 2 - Windows 7 (Temp Cleaner)
ECHO.
SET /P M=Select a number, then press ENTER: 
IF %M%==1 GOTO XP
IF %M%==2 GOTO 7

:XP
CLS
@COLOR 04
@ECHO OFF
setlocal enabledelayedexpansion
@ECHO.
@ECHO.
set i=0
@Echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
@ECHO º       Now Cleaning Your System      º
@Echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
@ECHO.
(Set /P j= ) < NUL

for /F "tokens=1 delims=[]" %%N in ('find /N ":StartOfCodeXP" ^<"%~f0"') do set start=%%N
for /F "tokens=1 delims=[]" %%N in ('find /N ":EndOfCodeXP"   ^<"%~f0"') do set /A lines=%%N - start
set line=0
for /F "skip=%start% usebackq tokens=* delims=" %%L in ("%~f0") do (
  call %%L 2>nul >nul
  set /P j=Û< NUL
  set /A line += 1
  set /A pct= line * 100 / lines
  title !pct!^% done
)  

GOTO Done

:StartofCodeXP
cd %SYSTEMDrive%\
RD /s /q "%WINDIR%\Prefetch"
RD /s /q "%TEMP%"
RD /s /q "%USERPROFILE%\Local Settings\Temp"
RD /s /q "%USERPROFILE%\Local Settings\Temporary Internet Files"
RD /s /q "%USERPROFILE%\Cookies"
RD /s /q "%SystemRoot%\Downloaded Program Files"
RD /s /q "%SystemRoot%\Temp"
RD /s /q "%SystemRoot%\tmp"
RD /s /q "C:\$Recycle.bin"
REM  ---Super File Cleaner
del /f /s /q %SystemDrive%\*.log
del /f /s /q %SystemDrive%\~*.*
del /f /s /q %SystemDrive%\*.tmp
del /f /s /q %SystemDrive%\*.bak
del /f /s /q %SystemDrive%\*.old
REM  ---END of Super File Cleaner
:EndOfCodeXP

:7
CLS
@COLOR 04
@ECHO OFF
setlocal enabledelayedexpansion
@ECHO.
@ECHO.
set i=0
@Echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
@ECHO º       Now Cleaning Your System      º
@Echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
@ECHO.
(Set /P j= ) < NUL

for /F "tokens=1 delims=[]" %%N in ('find /N ":StartOfCode7" ^<"%~f0"') do set start=%%N
for /F "tokens=1 delims=[]" %%N in ('find /N ":EndOfCode7"   ^<"%~f0"') do set /A lines=%%N - start
set line=0
for /F "skip=%start% usebackq tokens=* delims=" %%L in ("%~f0") do (
  call %%L 2>nul >nul
  set /P j=Û< NUL
  set /A line += 1
  set /A pct= line * 100 / lines
  title !pct!^% done
)  

GOTO Done

:StartOfCode7
cd /D %SYSTEMDrive%\
RD /s /q "%WINDIR%\Prefetch"
RD /s /q "%TEMP%"
RD /s /q "%USERPROFILE%\Local Settings\Temp"
RD /s /q "%USERPROFILE%\Local Settings\Temporary Internet Files"
RD /s /q "%USERPROFILE%\Cookies"
RD /s /q "%SystemRoot%\Downloaded Program Files"
RD /s /q "%SystemRoot%\Temp"
RD /s /q "%SystemRoot%\tmp"
RD /s /q "C:\$Recycle.bin"
REM  ---Super File Cleaner
del /f /s /q %SystemDrive%\*.log
del /f /s /q %SystemDrive%\~*.* 
del /f /s /q %SystemDrive%\*.tmp
del /f /s /q %SystemDrive%\*.bak
del /f /s /q %SystemDrive%\*.old
REM  ---END of Super File Cleaner
:EndOfCode7

:Done
CLS
@COLOR 0A
@Echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
@Echo º      Your System is now Clean       º
@Echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
@PAUSE
CLS
GOTO MENU

Open in new window

Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
But why are you a) using a menu, and don't differ yourself?

for /F "tokens=4,5* delims=[].^ " %%A in ('ver') do (
   rem %%A.%%B =
   rem     5.0  W2000  
   rem     5.1  XP
   rem     5.2  W2003
   rem     6.0  Vista / W2008
   rem     6.1  W7
)

And why are you using different codes for XP and W7? You need to, to account for some differences in the profile folders, but your code does not reflect that - both StartOfCodexx are the same.