Total Commander Forum Index Total Commander
Форум поддержки пользователей Total Commander
Сайты: Все о Total Commander | Totalcmd.net | Ghisler.com | RU.TCKB
 
 RulesRules   SearchSearch   FAQFAQ   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Подсчет строк в текстовых файлах

 
Post new topic   Reply to topic    Total Commander Forum Index -> Автоматизация Total Commander printer-friendly view
View previous topic :: View next topic  
Author Message
DoctorIkari



Joined: 28 Feb 2010
Posts: 53
Location: Nihon

Post (Separately) Posted: Thu Apr 21, 2011 10:47    Post subject: Подсчет строк в текстовых файлах Reply with quote

Как можно реализовать следующее: есть папка, в ней вложенные папка. В них случайно разбросаны текстовые файлы. Нужно подсчитать количество строк в этих файлах следующим образом:
1. количество непустых строк во всех файлах .cpp
2. количество всех строк во всех файлах .cpp
3. количество непустых строк во всех файлах .h
4. количество всех строк во всех файлах .h
5. количество всех строк
(это если курсор стоит на каталоге или пустом месте)

Если перевести курсор на файл - считывает только из него.
Куда выводить результат - не имеет значения Smile
?

 !  Avada:
Перенесено из "Общих вопросов" в более подходящий подфорум.

_________________
The right man in the wrong place can make all the difference in the world... (hl2)
Back to top
View user's profile Send private message Yahoo Messenger
Tol!k



Joined: 01 Apr 2008
Posts: 1727
Location: Арзамас

Post (Separately) Posted: Thu Apr 21, 2011 17:36    Post subject: Reply with quote

Просить автора wcx_LineCount
Back to top
View user's profile Send private message
Lev



Joined: 02 Mar 2005
Posts: 392

Post (Separately) Posted: Thu Apr 21, 2011 20:25    Post subject: Reply with quote

Попробуй так:
Code:
'запуск - wscript "диск:\путь\h_cpp_counter.vbs"
'параметры - %P%N

Dim stringscount, emptystrings, count_a, ccount_e,ccount,hcount_e,hcount

Set FSO = CreateObject("Scripting.FileSystemObject")

FF = WScript.Arguments(0)

Set re = New RegExp
re.Global=True
re.Multiline = True
re.Pattern="^\s*?$"

If FSO.FileExists(FF) Then
  FileProc ff
Else
  FolderProc ff
End If

MsgBox ff & vbCrLf & _
  "-----" & vbCrLf & _
  "строк в *.h файлах - " & hcount & vbCrLf & _
  "непустых строк в *.h файлах - " & hcount-hcount_e & vbCrLf & _
  "строк в *.cpp файлах - " & ccount & vbCrLf & _
  "непустых строк в *.cpp файлах - " & ccount-ccount_e & vbCrLf & _
  "-----" & vbCrLf & _
  "всего строк - " & count_a

Sub FolderProc(fPath)
  Dim loF
  Set loF = FSO.GetFolder(fPath)
  For Each F In loF.SubFolders
    F = F.Path
    FolderProc F
  Next
  For Each F In loF.Files
    F = F.Path
    FileProc F
  Next
  Set loF = Nothing
End Sub

Sub FileProc(f)
  Select Case LCase(FSO.GetExtensionName(f))
  Case "h"
    count(f)
    hcount=hcount + stringscount
    hcount_e=hcount_e + emptystrings
    count_a=count_a + stringscount
  Case "cpp"
    count(f)
    ccount=ccount + stringscount
    ccount_e=ccount_e + emptystrings
    count_a=count_a + stringscount
  End Select
End Sub

Sub count(f)
  If fso.GetFile(f).Size Then
    t=FSO.OpenTextFile(f).ReadAll
    stringscount = UBound(Split(t, vbNewLine)) + 1
    emptystrings=re.Execute(t).Count - stringscount + 1
  End If
End Sub
Back to top
View user's profile Send private message
DoctorIkari



Joined: 28 Feb 2010
Posts: 53
Location: Nihon

Post (Separately) Posted: Thu Apr 21, 2011 23:26    Post subject: Reply with quote

Спасибо! Все отлично Smile
//Вопросов больше нет. Тема закрыта.
_________________
The right man in the wrong place can make all the difference in the world... (hl2)
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Total Commander Forum Index -> Автоматизация Total Commander All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group