China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-11 13:41
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » File Line Count Statistics View 1,082 Replies 8
Original Poster Posted 2009-03-02 01:43 ·  中国 北京 朝阳区 联通
新手上路
Credits 4
Posts 4
Joined 2009-03-01 07:29
17-year member
UID 140268
Gender Male
Status Offline
I have several hundred files with the extensions: xls, xlsx, txt. Now I want to count the number of lines in each file (blank lines not included). These files are in a folder and its subfolders, and I also want the directories listed. Does anyone have a good way to solve this? Thanks in advance!!!!
Floor 2 Posted 2009-03-02 02:03 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
::Drag a directory onto this batch file, or specify a directory in %1, otherwise process the current directory
::The filenames of the specified types under this directory and all subdirectories, together with their line counts, are saved as a list in list.txt

@echo off
set dir=
set "dir=%~dp1\"
for /f "delims=" %%a in ('dir /b /s /a-d %dir% *.xls *.xls *.txt') do (
set/a n=0
for /f %%b in ('type "%%a"') do set/a n+=1
call echo.%%a has %%n%% lines
)>%temp%\list.txt
move %temp%\list.txt %dir%list.txt
精简
=> 个人网志
Floor 3 Posted 2009-03-02 02:59 ·  中国 北京 朝阳区 联通
新手上路
Credits 4
Posts 4
Joined 2009-03-01 07:29
17-year member
UID 140268
Gender Male
Status Offline
I ran it according to the code given in reply #2,

but it doesn't work. I tried it and there was no response for a long time. My filenames contain Chinese characters. Why is that?
Floor 4 Posted 2009-03-02 04:13 ·  中国 北京 朝阳区 联通
新手上路
Credits 4
Posts 4
Joined 2009-03-01 07:29
17-year member
UID 140268
Gender Male
Status Offline
Why is nobody answering? Doesn't anyone know how to do this?
Floor 5 Posted 2009-03-02 04:57 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 6 Posted 2009-03-02 07:47 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Your files aren't plain text, right!?
If that's the case, better not use BAT. At least I can't do it.
精简
=> 个人网志
Floor 7 Posted 2009-03-02 08:46 ·  中国 北京 朝阳区 联通
新手上路
Credits 4
Posts 4
Joined 2009-03-01 07:29
17-year member
UID 140268
Gender Male
Status Offline
Yes, not all of my files are text files. There are also .xls and .xlsx files. Is there any other way?
Floor 8 Posted 2009-03-02 09:43 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
No
精简
=> 个人网志
Floor 9 Posted 2009-03-02 20:00 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
Originally posted by boy7470 at 2009-3-2 08:46:
Yes, not all of my files are text files. There are also .xls and .xlsx files. Is there any other way?


For office documents you should consider using VBS, VBA, or python

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Forum Jump: