简体   繁体   中英

Batch File to Loop Through Each File in Directory and Count Records in Each File

I am trying to create a "Checking" batch file for an FTP process to ensure no data is lost via the FTP transmission.

The batch file needs to look at every single file inside a directory and and count the number of records. The result will be delimited by ~ (ie Output1~200). So far I've gotten this:

type "">Check.txt
set file=Output1.txt
set /a cnt=0
for /f %%a in ('type "%file%"^|find "" /v /c') do set /a cnt=%%a
echo %file%~%cnt% >> Check.txt

pause

The first type "">Check.txt is to clear the file then it looks for a specific file. How do I set this to loop therough all the file names within the directory dynamically?

This uses your code and processes every file in the directory - and counts the number of lines. Is that what you wanted to do?

@echo off
( 
  for %%a in (*.*) do (
    for /f %%b in (' find "" /v /c ^< "%%a" ') do echo %%a~%%b
  )
)> "%userprofile%\desktop\Check.txt"

Batch file links and help

For built in help on commands & syntax, type this in a cmd window

For W2K: HH windows.chm::ntcmds.htm
For XP: HH ntcmds.chm

Some batch related forums and material

http://www.dostips.com/forum/
http://www.ss64.com/nt/index.html
http://www.robvanderwoude.com/
http://www.computerhope.com/forum/
http://stackoverflow.com
http://forums.techguy.org/23-dos-other/
http://www.netikka.net/tsneti/info/tscmd.php <--- tscmd.zip has many samples

Search these Usenet groups. Replace "your+keywords" with your keywords

alt.msdos.batch
alt.msdos.batch.nt
http://groups.google.com/groups?group=alt.msdos.batch&q=your+keywords
http://groups.google.com/groups?group=alt.msdos.batch.nt&q=your+keywords

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM