Methical
Methical

Reputation:

Number of files deleted from batch file

REM Detect how many files are on the C: drive
dir /s /b C:\ |find /c "\" > NUMfiles.###
set /p count1=<NUMfiles.###

##### TEMP FILES DELETED HERE, RUN CCLEANER, RUN MBAM, ETC #####

REM Calculate Total Files Deleted
dir /s /b C:\ |find /c "\" > NUMfiles.###
set /p count2=<NUMfiles.###
set /a count3=%count1% - %count2%
echo Number of files removed: %count3%

This doesn't seem to be giving me an accurate reading. Can anyone help? I do a manual check via command line using the 'dir /s /b C:\ |find /c "\"' before the script, and at the end. And the output from '%count3% isn't accurate from my subtraction from the manual checks. Hope you understand my question.

Upvotes: 1

Views: 2188

Answers (2)

Jay
Jay

Reputation: 1655

Yes, as snemarch montined, the fact that you list everything and temporary files could as well be added/deleted by another process meanwhile invalidate the entire effort.

On a side note, adding "/a-d" to the "dir" command would remove the directories from being listed, thus not needing VonC's "find /v "" addition to the process, if you insist on checking files only.

Could you not check file while they get deleted instead? Not sure what you use this for but you definately need to rethink the way from source, the deleting part.

My suggestion.

Upvotes: 1

VonC
VonC

Reputation: 1326716

If you must iterate on the all content, this command line might be more precise to list the number of files (files, not directories):

dir /a /s /OG C:\ |find /v "<DIR>" | find /c "M "

Off course, this assume a dir does display 'AM ' or 'PM '.

If it does not, the following should works better:

dir /a /s /OG C:\ |find /v "<DIR>" | find /c "/"

Upvotes: 0

Related Questions