|
Answer» I would like to do the above and then if the number of files is larger then what I specify, have it email me and tell me that the number of files has been exceeded. Any advice on this would be great.I don't THINK MS-DOS can email, if anyone knows different, tell please. I am like 90% sure I'm RIGHT on this.there are probably programs that could be invoked from the command-line to E-mail.
as for counting the number of files, I'd imagine it would involve sending the output to FIND, and finding the last line with "File(s)", and then grabbing the number before that and comparing it to the value your checking for. If it is larger, you would invoke the e-mail sending program with appropriate arguments.
The attackment should do what you want, it will count files and folders in the directiory that the program is placed in. It is not as easy as you would think so I dout it to be in any book because this is really complicated batch stuff that what you are asking gets into.
Hope you like, but since the code is quite difficult the app is and EXE, Tan_Za
[attachment deleted by admin]Here is my version:
the only real thing I could think of was (ASIDE from not search subdirectories(?)) was that it included all the directories in the file count.
In order to remedy this, I used a switch on dir to exclude directories.
Code: [Select]@echo off title File Counter batch. :recurse set I=1
echo "files in folder" cd REM view all files, EXCEPT directories. FOR /f "tokens=*" %%P IN ('dir /A-d /b') do (call :showfiles "%%P") echo Filecount: %I% REM now call on all subfolders...
:showfiles echo %1 set /a I+=1 GOTO :eof
for the record, Tan_Za's code would be:
Code: [Select]@echo off title File Counter by Tan_Za SET count=1 FOR /f "tokens=*" %%G IN ('dir /b') DO (call :s_do_sums "%%G") echo Any key to continue echo made by Tan_Za. any questions email me at:[emailprotected]l.com pause >nul GOTO :eof :s_do_sums echo %count%:%1 set /a count+=1 GOTO :eof
your measly EXE compression does nothing to dissuade me! MWA HA HA *cough*.
also, the recurse: label was a remnant from my almost successful attempt to iterate through subdirectories by afterwards using dir /b /ad in the for command to iterate on each folder and recurse on it with the batch file. Turns out batch files don't like recursion.Yeah batch to exe is a very easy thing to do and to reverse lol, but my code is a little complex for some peole because it sure took a while to do.
DAM you...
Not really, thats ok, Tan_ZaIf you want to count all the files in the subdirectories as well (also it's smaller than the other two's) this should work:
Code: [Select]@echo off setlocal enabledelayedexpansion
for /f %%A in ('dir /s ^| find "File(s)"') do (set B=%%A+!B!) set B=%B%0 set /a C=%B% echo %C pause exit FBBC programmer, you're batch file counted the files. But then it just exited out. Quote from: BatchFileCommand on January 10, 2009, 01:11:52 PM BC programmer, you're batch file counted the files. But then it just exited out.
ahh yes, just add "Pause" right before the ":showfiles" line. It still doesn't seem to work, it pauses in the beginning before it counts the file. I need it to pause after it's counted all the files.don't put pause at the end of the batch, but rather in the same area that Tan_Za has placed their pause, which is right before the subroutine.
here, I also fixed a bug involving a forgotten GOTO :EOF, not sure if it was affecting the program or not, though.
Code: [Select]@echo off title File Counter batch. :recurse set I=1
echo "files in folder" cd REM view all files, EXCEPT directories. FOR /f "tokens=*" %%P IN ('dir /A-d /b') do (call :showfiles "%%P") echo Filecount: %I% REM now call on all subfolders...
PAUSE
goto :eof :showfiles echo %1 set /a I+=1 goto :eof What's wrong with:
dir /b /s /A-d c:\temp | find "" /v /n /c
You can use blat (www.blat.net) to send the email Quote from: rbird on February 11, 2009, 03:18:57 AMWhat's wrong with:
dir /b /s /A-d c:\temp | find "" /v /n /c
why, it's too easy, of course! redirect that to a variable and he'd be good to go
bit of a topic bump, but for a good reason from somebody who knows their switches .
EDIT: welcome to CH!Hello All,
I would like to count the number of files from a folder and only count the files from yesterday. And email the count to a specific email address. I would set this on a Task Scheduler to daily to get a count and see how many files are added to the folder. I tried creating a batch file dir /a "C:xx\" |find /c /v ""
But this gives me a count of everything in the folder, i just need a count from yesterday and also i dont know how to email the count. Please help!Quote from: TechAbhi on May 16, 2010, 11:55:42 AMHello All,
I would like to count the number of files from a folder and only count the files from yesterday. And email the count to a specific email address. I would set this on a Task Scheduler to daily to get a count and see how many files are added to the folder. I tried creating a batch file dir /a "C:xx\" |find /c /v ""
But this gives me a count of everything in the folder, i just need a count from yesterday and also i dont know how to email the count. Please help!
Please make your own thread instead of bumping one from last year.
|