Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: I need some math help  (Read 3031 times)

0 Members and 1 Guest are viewing this topic.

TheShadow

    Topic Starter


    Hopeful

  • Retiree in Florida
  • Thanked: 13
    • Yes
    • The Doctor
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Windows XP
I need some math help
« on: October 05, 2011, 07:28:46 AM »
I've written this little batch file that counts the number of files on the hard drive,
then deletes all the files in designated folders (junk files).
Then it counts the files again.

Both starting and ending counts are shown in the DOS window and they are also put into little text files in the root directory.
My desire, not a necessity, is to be able, within the batch file, to subtract the ending count from the beginning count and display it on the screen.  I just don't know how to do math within a batch file.  It's not something I've ever needed to do before.

Here's my XPCleanup.bat file.  Maybe someone could help me do the math.  Eh?

Quote
Rem: Count the number of files on "C" before the cleanup.
@Echo off
cls
Echo:  Performing initial file count. Please wait!
dir /a /s "C:\" |find /c /v "" >C:\StartCt.txt
Echo:  My initial File Count, Before Cleaning:
type C:\FirstCln.txt

Echo:  Disk Cleanup now starting.  Please Wait!
@Echo off
del /F /S /Q "C:\temp\*.*" >nul
del /F /S /Q "%systemroot%\temp\*.*" >nul
del /F /S /Q "%systemroot%\SYSTEM32\config\systemprofile\Local 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
Rem:  the following line deletes the Virus Vault for AVG 2012 anti-virus program.
del /F /S /Q "C:\$AVG\$VAULT\*.fil" >nul
del /F /S /Q "D:\$AVG\$VAULT\*.fil" >nul
del /F /S /Q "C:\$Recycle.Bin.Bin\*.*"
del /F /S /Q "C:\Recycled\*.*"
Echo:  Disk Cleanup is now complete.
Rem: Show number of files left on HD after the cleanup.

@Echo off
Echo:  Performing File Count, After Cleaning.  Please Wait!
dir /a /s "C:\" |find /c /v "" >C:\endct.txt
Echo:
Echo: My file count after cleaning
type C:\endct.txt
pause

The batch file works great as written.  One friend in Cal. used the batch file on his own computer, which he had already cleaned with other programs and the batch file found and removed 940 files.  As I find more hiding places for junk files, those paths will be added to the program.

But if anyone knows how to do the math in this batch file and print the result on the screen, I'll be forever in your debt.

Cheers Mates!
The Shadow  8)



Experience is truly the best teacher.
Backup! Backup! Backup!  Ghost Rocks!

Salmon Trout

  • Guest
Re: I need some math help
« Reply #1 on: October 05, 2011, 11:49:27 AM »
Code: [Select]
Rem: Count the number of files on "T" before the cleanup.
@Echo off

REM CREATE SOME FILES TO CLEAN UP

md T:\cleanup
for /l %%N in (1,1,500) do (
echo hello > T:\Cleanup\Trash-%%N.txt
)

Echo:  Performing initial file count. Please wait!
for /f "delims=" %%A in ('dir /a /s "T:\" ^| find /c /v ""') do set Count1=%%A
Echo File Count before cleaning: %Count1% files

Echo:  Disk Cleanup now starting.  Please Wait!
del /F /S /Q "T:\cleanup\*.*">nul

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 "T:\" ^| find /c /v ""') do set Count2=%%A
set /a deleted=%Count1%-%Count2%
Echo File count after cleaning:  %Count2%  files
Echo Files deleted:              %deleted% files
pause

Salmon Trout

  • Guest
Re: I need some math help
« Reply #2 on: October 05, 2011, 12:40:13 PM »
Some comments added...

Code: [Select]
Rem: Count the number of files on "T" before the cleanup.
@Echo off

REM CREATE SOME FILES TO CLEAN UP

md T:\cleanup
for /l %%N in (1,1,500) do (
echo hello > T:\Cleanup\Trash-%%N.txt
)

Echo:  Performing initial file count. Please wait!

REM This is a way to count the files without using a temporary file
REM by using FOR to capture the output of dir and putting it
REM into a variable
REM You have to escape the pipe character | with a caret ^
REM Notice the single quotes

for /f "delims=" %%A in ( ' dir /a /s "T:\" ^| find /c /v "" ' ) do set Count1=%%A

Echo File Count before cleaning: %Count1% files

Echo:  Disk Cleanup now starting.  Please Wait!
del /F /S /Q "T:\cleanup\*.*">nul

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 "T:\" ^| find /c /v "" ' ) do set Count2=%%A

REM You can use SET with the /a switch to do arithmetic
REM example set /a number3=%number2%-%number1%
REM You can add spaces either side of the + - * / symbols
REM Type set /? for documentation
set /a deleted=%Count1% - %Count2%

Echo File count after cleaning:  %Count2%  files
Echo Files deleted:              %deleted% files
pause

Darth



    Starter

    • Experience: Beginner
    • OS: Unknown
    Re: I need some math help
    « Reply #3 on: October 05, 2011, 04:39:35 PM »
    This may be a better for loop...

    for /f "tokens=1-4 delims= " %A in ( 'dir /a:-d /s "D:\cleanup" ^| find "File
    "' ) do set Count2=%A

    Your math may be a little more accurate to look up files only. Unless you want to search for system files.

    TheShadow

      Topic Starter


      Hopeful

    • Retiree in Florida
    • Thanked: 13
      • Yes
      • The Doctor
    • Certifications: List
    • Computer: Specs
    • Experience: Guru
    • OS: Windows XP
    Re: I need some math help
    « Reply #4 on: October 06, 2011, 06:04:43 AM »
    Thank y'all for your help.
    I've transferred the formulas into my own batch file with total success.

    Here's an edited readout, when I ran the new batch file on my own PC, just now.

      Performing initial file count. Please wait!
    File Count before cleaning: 63705 files
    Press any key to continue . . .
      Disk Cleanup now starting.  Please Wait!

    Rem:  Disk Cleanup messages shown here.
    The system cannot find the file specified.
      Disk Cleanup is now complete.
      Performing File Count, After Cleaning.  Please Wait!
    File count after cleaning:  63453  files
    Files deleted:              252 files
    Press any key to continue . . .


    I'm appalled but not overly surprised at just how fast Windows collects junk files.
    I've been running cleanup batch files for years, going all the way back to Windows 98,
    but it's just now that I'm getting really serious about it.  I've even added lines to
    empty the Recycle Bins and to empty the AVG Virus Vaults.

    When I clean up a customer's PC and tweak and tune it for optimum performance,
    I leave a copy of my cleanup batch file, minus the file counts and pauses, in their
    startup folder, for a daily cleanup.  That prevents the huge buildup of junk files on
    their hard drives.  I call that my "Free Maid Service".

    I run another cleanup program that does give me a file count and megabyte count,
    when it removes "Unnecessary Files".  On an initial cleanup of a customers PC that's
    had no service, it's not at all unusual for that program to find well over 100,000 files.

    Again, 'Thank You' (all) for your help.   Mission accomplished!
    Mark up another success for the "Computer Hope" forum.

    Remember Steve Jobs

    The Shadow 8)
    « Last Edit: October 06, 2011, 06:17:18 AM by TheShadow »
    Experience is truly the best teacher.
    Backup! Backup! Backup!  Ghost Rocks!

    Salmon Trout

    • Guest
    Re: I need some math help
    « Reply #5 on: October 06, 2011, 06:25:17 AM »
    It's a myth that periodically cleaning out the Prefetch folder "improves performance". Ryan Myers, a developer on Microsoft’s Windows Client Performance Team, says: "XP systems have a Prefetch directory underneath the windows root directory, full of .pf files — these are lists of pages to load. The file names are generated from hashing the EXE to load — whenever you load the EXE, we hash, see if there’s a matching (exename)-(hash).pf file in the prefetch directory, and if so we load those pages. (If it doesn’t exist, we track what pages it loads, create that file, and pick a handful of them to save to it.) So, first off, it is a bad idea to periodically clean out that folder as some tech sites suggest. For one thing, XP will just re-create that data anyways; secondly, it trims the files anyways if there’s ever more than 128 of them so that it doesn’t needlessly consume space. So not only is deleting the directory totally unnecessary, but you’re also putting a temporary dent in your PC’s performance".

    Bottom line: You will not improve Windows performance by cleaning out the Prefetch folder. You will, in fact, degrade Windows performance by cleaning out the Prefetch folder.