1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with Dos For/F command and sub folders

Discussion in 'Windows XP' started by Dazza, Mar 23, 2010.

  1. Dazza

    Dazza Flightless Bird

    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 count the
    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
     
  2. Pegasus [MVP]

    Pegasus [MVP] Flightless Bird

    "Dazza" <darren@taylorhouse.co.uk> 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 count the
    > 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
    )
     
  3. Dazza

    Dazza Flightless Bird

    On 23 Mar, 12:49, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    > "Dazza" <dar...@taylorhouse.co.uk> 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 count the
    > > 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
     
  4. Dazza

    Dazza Flightless Bird

    On 23 Mar, 13:07, Dazza <dar...@taylorhouse.co.uk> wrote:
    > On 23 Mar, 12:49, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    >
    >
    >
    >
    >
    > > "Dazza" <dar...@taylorhouse.co.uk> 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 count the
    > > > 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?????
     
  5. John John - MVP

    John John - MVP Flightless Bird

    Dazza wrote:
    > On 23 Mar, 13:07, Dazza <dar...@taylorhouse.co.uk> wrote:
    >> On 23 Mar, 12:49, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    >>
    >>
    >>
    >>
    >>
    >>> "Dazza" <dar...@taylorhouse.co.uk> 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 count the
    >>>> 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!
     
  6. Pegasus [MVP]

    Pegasus [MVP] Flightless Bird

    "John John - MVP" <audetweld@nbnet.nb.ca> wrote in message
    news:uFaKyzoyKHA.244@TK2MSFTNGP06.phx.gbl...
    > Dazza wrote:
    >> On 23 Mar, 13:07, Dazza <dar...@taylorhouse.co.uk> wrote:
    >>> On 23 Mar, 12:49, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>> "Dazza" <dar...@taylorhouse.co.uk> 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 count the
    >>>>> 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
    )
     
  7. Dazza

    Dazza Flightless Bird

    On 23 Mar, 21:50, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    > "John John - MVP" <audetw...@nbnet.nb.ca> wrote in messagenews:uFaKyzoyKHA.244@TK2MSFTNGP06.phx.gbl...
    >
    >
    >
    >
    >
    > > Dazza wrote:
    > >> On 23 Mar, 13:07, Dazza <dar...@taylorhouse.co.uk> wrote:
    > >>> On 23 Mar, 12:49, "Pegasus [MVP]" <n...@microsoft.com> wrote:

    >
    > >>>> "Dazza" <dar...@taylorhouse.co.uk> 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 count the
    > >>>>> 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
     
  8. Pegasus [MVP]

    Pegasus [MVP] Flightless Bird

    "Dazza" <darren@taylorhouse.co.uk> wrote in message
    news:791e4f5b-4e5f-4a2d-bb45-2b88dd14bf00@y17g2000yqd.googlegroups.com...
    > On 23 Mar, 21:50, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    >> "John John - MVP" <audetw...@nbnet.nb.ca> wrote in
    >> messagenews:uFaKyzoyKHA.244@TK2MSFTNGP06.phx.gbl...
    >>
    >>
    >>
    >>
    >>
    >> > Dazza wrote:
    >> >> On 23 Mar, 13:07, Dazza <dar...@taylorhouse.co.uk> wrote:
    >> >>> On 23 Mar, 12:49, "Pegasus [MVP]" <n...@microsoft.com> wrote:

    >>
    >> >>>> "Dazza" <dar...@taylorhouse.co.uk> 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 count the
    >> >>>>> 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* you start
    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
     
  9. Dazza

    Dazza Flightless Bird

    On 29 Mar, 12:45, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    > "Dazza" <dar...@taylorhouse.co.uk> wrote in message
    >
    > news:791e4f5b-4e5f-4a2d-bb45-2b88dd14bf00@y17g2000yqd.googlegroups.com...
    >
    >
    >
    >
    >
    > > On 23 Mar, 21:50, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    > >> "John John - MVP" <audetw...@nbnet.nb.ca> wrote in
    > >> messagenews:uFaKyzoyKHA.244@TK2MSFTNGP06.phx.gbl...

    >
    > >> > Dazza wrote:
    > >> >> On 23 Mar, 13:07, Dazza <dar...@taylorhouse.co.uk> wrote:
    > >> >>> On 23 Mar, 12:49, "Pegasus [MVP]" <n...@microsoft.com> wrote:

    >
    > >> >>>> "Dazza" <dar...@taylorhouse.co.uk> 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 count the
    > >> >>>>> 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* you start
    > 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
     
  10. Dazza

    Dazza Flightless Bird

    On 29 Mar, 13:21, Dazza <dar...@taylorhouse.co.uk> wrote:
    > On 29 Mar, 12:45, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    >
    >
    >
    >
    >
    > > "Dazza" <dar...@taylorhouse.co.uk> wrote in message

    >
    > >news:791e4f5b-4e5f-4a2d-bb45-2b88dd14bf00@y17g2000yqd.googlegroups.com....

    >
    > > > On 23 Mar, 21:50, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    > > >> "John John - MVP" <audetw...@nbnet.nb.ca> wrote in
    > > >> messagenews:uFaKyzoyKHA.244@TK2MSFTNGP06.phx.gbl...

    >
    > > >> > Dazza wrote:
    > > >> >> On 23 Mar, 13:07, Dazza <dar...@taylorhouse.co.uk> wrote:
    > > >> >>> On 23 Mar, 12:49, "Pegasus [MVP]" <n...@microsoft.com> wrote:

    >
    > > >> >>>> "Dazza" <dar...@taylorhouse.co.uk> 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 count the
    > > >> >>>>> 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 issueof
    > > 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* you start
    > > 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
     
  11. Dazza

    Dazza Flightless Bird

    On 30 Mar, 13:12, Dazza <dar...@taylorhouse.co.uk> wrote:
    > On 29 Mar, 13:21, Dazza <dar...@taylorhouse.co.uk> wrote:
    >
    >
    >
    >
    >
    > > On 29 Mar, 12:45, "Pegasus [MVP]" <n...@microsoft.com> wrote:

    >
    > > > "Dazza" <dar...@taylorhouse.co.uk> wrote in message

    >
    > > >news:791e4f5b-4e5f-4a2d-bb45-2b88dd14bf00@y17g2000yqd.googlegroups.com....

    >
    > > > > On 23 Mar, 21:50, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    > > > >> "John John - MVP" <audetw...@nbnet.nb.ca> wrote in
    > > > >> messagenews:uFaKyzoyKHA.244@TK2MSFTNGP06.phx.gbl...

    >
    > > > >> > Dazza wrote:
    > > > >> >> On 23 Mar, 13:07, Dazza <dar...@taylorhouse.co.uk> wrote:
    > > > >> >>> On 23 Mar, 12:49, "Pegasus [MVP]" <n...@microsoft.com> wrote:

    >
    > > > >> >>>> "Dazza" <dar...@taylorhouse.co.uk> 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
     
  12. Pegasus [MVP]

    Pegasus [MVP] Flightless Bird

    "Dazza" <darren@taylorhouse.co.uk> wrote in message
    news:42c92294-55dc-470d-b642-5dc22f512683@r27g2000yqn.googlegroups.com...
    > On 29 Mar, 13:21, Dazza <dar...@taylorhouse.co.uk> wrote:
    >> On 29 Mar, 12:45, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    >>
    >>
    >>
    >>
    >>
    >> > "Dazza" <dar...@taylorhouse.co.uk> wrote in message

    >>
    >> >news:791e4f5b-4e5f-4a2d-bb45-2b88dd14bf00@y17g2000yqd.googlegroups.com...

    >>
    >> > > On 23 Mar, 21:50, "Pegasus [MVP]" <n...@microsoft.com> wrote:
    >> > >> "John John - MVP" <audetw...@nbnet.nb.ca> wrote in
    >> > >> messagenews:uFaKyzoyKHA.244@TK2MSFTNGP06.phx.gbl...

    >>
    >> > >> > Dazza wrote:
    >> > >> >> On 23 Mar, 13:07, Dazza <dar...@taylorhouse.co.uk> wrote:
    >> > >> >>> On 23 Mar, 12:49, "Pegasus [MVP]" <n...@microsoft.com> wrote:

    >>
    >> > >> >>>> "Dazza" <dar...@taylorhouse.co.uk> 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 count
    >> > >> >>>>> the
    >> > >> >>>>> 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* you
    >> > start
    >> > 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


    This is the way I designed it, based on your somewhat vague specification.
     
  13. Pegasus [MVP]

    Pegasus [MVP] Flightless Bird

    "Dazza" <darren@taylorhouse.co.uk> wrote in message
    news:fce0aad9-e4fc-42ed-8f58-a07cbd6d8e5c@b33g2000yqc.googlegroups.com...
    > On 29 Mar, 12:45, "Pegasus [MVP]" <n...@microsoft.com> wrote:


    >
    > 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


    Try this batch file. It generates the results you expect but I'm not fond of
    it for two reasons:
    - It will be slow for large files and also for large numbers of files
    - It is likely to get derailed by poison characters either in the file names
    or in the file contents.
    @echo off
    SetLocal EnableDelayedExpansion
    set Folder=d:/Test
    echo Lines Commas Path
    for /F "delims=" %%a in ('dir "%Folder%\*.txt" /b /s') do (
    set C=0
    set L=0
    for /F %%c in ('type "%%a" ^| find /c ","') do set C=%%c
    for /F %%L in ('type "%%a"') do set /a L=!L!+1
    set C= !C!
    set L= !L!
    echo !L:~-6! !C:~-5! %%a
    )
     
  14. Pegasus [MVP]

    Pegasus [MVP] Flightless Bird

    "Dazza" <darren@taylorhouse.co.uk> wrote in message
    news:4ccd9a08-3351-4f44-8605-1ea4ab4052cd@y17g2000yqd.googlegroups.com...
    > On 30 Mar, 13:12, Dazza <dar...@taylorhouse.co.uk> wrote:


    > 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


    You need to scan each file twice: Once to count the commas and once to count
    the lines. Your code uses a nested loop which causes the files to be scanned
    L squared times (L = number of lines in each file).
     

Share This Page