On 30 Mar, 13:12, Dazza wrote:
> On 29 Mar, 13:21, Dazza wrote:
>
>
>
>
>
> > On 29 Mar, 12:45, "Pegasus [MVP]" wrote:
>
> > > "Dazza" wrote in message
>
> > >news:791e4f5b-4e5f-4a2d-bb45-2b88dd14bf00@y17g2000yqd.googlegroups.com....
>
> > > > On 23 Mar, 21:50, "Pegasus [MVP]" wrote:
> > > >> "John John - MVP" wrote in
> > > >> messagenews:uFaKyzoyKHA.244@TK2MSFTNGP06.phx.gbl...
>
> > > >> > Dazza wrote:
> > > >> >> On 23 Mar, 13:07, Dazza wrote:
> > > >> >>> On 23 Mar, 12:49, "Pegasus [MVP]" wrote:
>
> > > >> >>>> "Dazza" wrote in message
> > > >> >>>>news:c622bf0e-e7b3-489f-b204-74c0e73071e0@15g2000yqi.googlegroups.com...
> > > >> >>>>> Hi Guys
> > > >> >>>>> Its one of those days when you say yes that can be done. Only to
> > > >> >>>>> find
> > > >> >>>>> out you start wishing you had said no!
> > > >> >>>>> I need to inspect each .txt file in each subfolder and countthe
> > > >> >>>>> number of commas are in it and then list them
> > > >> >>>>> i know i am missing something and must be my age
> > > >> >>>>> @echo off
> > > >> >>>>> setlocal enabledelayedexpansion
> > > >> >>>>> for /F "usebackq" %%a IN ('*.txt') Do find /c /i "," %%a >>c:
> > > >> >>>>> \commareport.txt
> > > >> >>>>> This works fine for the folder is is in but i need to do all
> > > >> >>>>> subfolders
> > > >> >>>>> I have tried calling this bat from another bat but with no results.
> > > >> >>>>> Can anyone give me a hand,
> > > >> >>>>> Cheers
> > > >> >>>>> Darren
> > > >> >>>> Here you go:
> > > >> >>>> @echo off
> > > >> >>>> for /F %%a in ('dir *.txt /b /s') do (
> > > >> >>>> Â for /F %%c in ('type "%%a" ^| find /c ","') do echo %%c -%%a
> > > >> >>>> )- Hide quoted text -
> > > >> >>>> - Show quoted text -
> > > >> >>> Many Thanks for the quick reply, the only problem i have now is that
> > > >> >>> the are spaces in the folder names, legacy dont you love it.....
>
> > > >> >>> Darren- Hide quoted text -
>
> > > >> >>> - Show quoted text -
>
> > > >> >> Any Body got any ideas?????
>
> > > >> > Hang tight... you're being helped by one of the best and he won't
> > > >> > abandon
> > > >> > you halfway through the job. Â His last post was less than 27 minutes
> > > >> > ago,
> > > >> > he is active in several groups, give him time to come back and read
> > > >> > your
> > > >> > other post!
>
> > > >> To John: Thanks for the compliment, which is not really deserved. And
> > > >> yes, I
> > > >> sometimes do have some other commitments.
>
> > > >> To the OP: Sorry for the oversight. Here you go again:
> > > >> @echo off
> > > >> for /F "delims=" %%a in ('dir *.txt /b /s') do (
> > > >> Â for /F %%c in ('type "%%a" ^| find /c ","') do echo %%c - %%a
> > > >> )- Hide quoted text -
>
> > > >> - Show quoted text -
>
> > > > Hi Thanks for the quick update.
>
> > > > Sorry I did not get to you but i have been on a few days vacation.
>
> > > > This now works a treat, but like all requests they change the goal
> > > > posts.
>
> > > > I have now been asked to add the number of lines in each text file
> > > > also
>
> > > > I am on the catch up with being off
>
> > > > Regards
> > > > Darren
>
> > > Using a batch file to count the number of lines in a text file is
> > > notoriously hard because batch files have the unfortunate habit of ignoring
> > > blank lines when scanning text files. There is also the perennial issue of
> > > poison characters such as ()"`& that have a tendency to make the batch file
> > > unstable. The solution below uses a hybrid batch/VBS solution and is far
> > > more robust than a pure batch file. Since your specification is rather
> > > vague, you will probably have to tune it to deliver the results you expect.
> > > Or, in other words, you must nail down your requirements *before* youstart
> > > coding.
>
> > > @echo off
> > > set sFolder=d:\User Data
> > > set Scr="%temp%\TempVBS.vbs"
> > > set VB=echo^>^>%Scr%
> > > cd 1>nul 2>%Scr%
> > > %VB% '------------------------------------------
> > > %VB% 'Recursively count the number of .txt files
> > > %VB% 'and report the number of lines and commas
> > > %VB% '29.3.2010 FNL
> > > %VB% '------------------------------------------
> > > %VB% Set oFSO = CreateObject("Scripting.FileSystemObject")
> > > %VB% Set oFolder = oFSO.GetFolder("%sFolder%")
> > > %VB% iFileCount  = 0
> > > %VB% iLineCount  = 0
> > > %VB% iCommaCount = 0
> > > %VB% ProcessFolder(oFolder)
> > > %VB% WScript.Echo iFileCount, iLineCount, iCommaCount
> > > %VB% '----------------------------
> > > %VB% 'Process a folder recursively
> > > %VB% '----------------------------
> > > %VB% Sub ProcessFolder(oFldr)
> > > %VB% Â For Each oFile In oFldr.Files
> > > %VB% Â Â If lcase(Right(oFile.Name, 4)) = ".txt" then Count oFile
> > > %VB% Â Next
> > > %VB% Â For Each oSubFolder In oFldr.Subfolders
> > > %VB% Â Â ProcessFolder oSubFolder
> > > %VB% Â Next
> > > %VB% End Sub
> > > %VB% '---------------------
> > > %VB% 'Process a single file
> > > %VB% '---------------------
> > > %VB% Sub Count(oFile)
> > > %VB% Â WScript.Echo "Processing", oFile.path
> > > %VB% Â iFileCount = iFileCount + 1
> > > %VB% Â if oFile.size = 0 then Exit Sub
> > > %VB% Â Set oData = oFSO.OpenTextFile(oFile.path)
> > > %VB% Â sString = oData.ReadAll
> > > %VB% Â For i = 1 To Len(sString)
> > > %VB% Â Â char = Mid(sString, i, 1)
> > > %VB% Â Â if char = "," Â Then iCommaCount = iCommaCount + 1
> > > %VB% Â Â If char = vbLf then iLineCount = iLineCount + 1
> > > %VB% Â Next
> > > %VB% Â oData.close
> > > %VB% End Sub
> > > for /F "tokens=1-10" %%a in ('cscript //nologo %Scr%') do set Files=%%a& set
> > > Lines=%%b& set Commas=%%c
> > > del %Scr%
> > > echo %Files% files, %Lines% lines, %Commas% commas- Hide quoted text -
>
> > > - Show quoted text -
>
> > Hi Thanks again
>
> > I am sorry if i am not descripbing what i am needing to do very
> > clearly. I will try to explain
>
> > I have a folder with multiple subfolders. That contain a number
> > of .txt files. These file are text files of production serial numbers.
> > They are in a number of legacy formats.
>
> > However each serial number is either on its own line, or on its own
> > line followed by a commas or multiple numbers on one line but each
> > followed by a comma.
>
> > I need to be able to document the number of serial numbers is each
> > file. Your first bat file worked for 75% of the files but does not
> > work for the ones with no commas.
>
> > What i would like is to display the following
>
> > Lines       Commas        Path
> > 10000 Â Â Â Â Â 10000 Â Â Â Â Â Â Â Â Â /abc/def/ghi.txt
> > 500 Â Â Â Â Â Â Â Â 1500 Â Â Â Â Â Â Â Â Â /qwe/rty/uio.txt
> > 50000 Â Â Â Â Â Â Â Â Â 0 Â Â Â Â Â Â Â Â Â /qwe/rty/lmk/hij.txt
>
> > With these results i can identify the files that need a manual check.
>
> > I hope this is a little clearer
>
> > and i do appreciate your help
>
> > Darren- Hide quoted text -
>
> > - Show quoted text -
>
> I must be doing something wrong, i am trying the above script and it
> does not seem to be echoing anything to screen.
>
> After it has finished in i manually echo the end variable i get a
> result. but these seem to be a full total- Hide quoted text -
>
> - Show quoted text -
HI Pegasus
I have had no joy so far, but i have a solution if i can get it
together and could you help
For the commas this works
@echo off
for /F "delims=" %%a in ('dir *.txt /b /s') do (
for /F %%c in ('type "%%a" ^| find /c ","') do echo %%c # %%a
)
If i modify it i can get the same to count the lines
@echo off
for /F "delims=" %%a in ('dir *.txt /b /s') do (
for /F %%c in ('type "%%a" ^| find /v /c "%junk%"') do echo %%c # %
%a
)
I am struggling to get both find commands into the same for/f loop. i
am trying
@echo off
for /F "delims=" %%a in ('dir *.txt /b /s') do (
for /F %%c in ('type "%%a" ^| find /c ","') do (
for /F %%l in ('type "%%a" ^| find /v /c "%junk%"') do echo %%l # %
%c # %%a
)
Anybody got any ideas