Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Bat or VBS file to count a specific word in multiple word docs  (Read 12861 times)

0 Members and 1 Guest are viewing this topic.

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Bat or VBS file to count a specific word in multiple word docs
« Reply #15 on: October 10, 2009, 01:58:34 PM »
Dude, if you are going to provide him your solutions in full , go ahead. Depending on my mood, I am not obliged to solve everything for OP.

If i really want to nitpick about your code, i would do that, but i will not. for example, Input argument checking, input file format ambiguity, therefore, would you just give it a rest...



To sum it up.

Billrich. you are not a programmer. That in and of itself is not a problem- I am not a programmer by profession either- but I have actually read "real" programming books, including the language reference for a number of programming languages as well as their corresponding programmers guides, and I'm sure ghostdog has read a few as well. Not to mention Code Complete(bloody fine book), either. I wrote a complete replacement for the very same FileSystemObjects we are using here, that adds far too many features too count. Shall I present the code for that so you may point out if I should be calling CloseHandle() somewhere I forgot? Or will you actually understand that the class based implementation will call CloseHandle() in the Terminate Event. Or more precisely, do you understand events? Probably not.... but you know what? That's fine- Your Learning VBScript. This is good. It's good to ask questions about code. But to make declarations that the program doesn't work when the error message is quite plain is nothing short of plain ol' silly.

Was it a text file? come on, admit it. it was a text file you renamed to doc. it's ok. Have some pie. Not all of it, I want some.

I'm tired of your pedantic arguments against other peoples VBScript or Batch with some frivolous claims as "it does not work" because you can't figure out the commandline syntax, or because you decide that, despite any input format the OP defines, you'll call shenanigans because the batch or VBS script breaks when you insert characters, or because the code isn't "forward thinking" in your eyes, or some other futile attempt at whatever maligned argument you can muster, and if you can't think of any, you just make up some kind of analogy involving farm animals.


I might also add that the scripts I put up here I just kinda whip up as fast as possible. But I always test it. If not posting a "sample output" inconveniences you that's a *censored* shame.
I was trying to dereference Null Pointers before it was cool.

billrich

  • Guest
Re: Bat or VBS file to count a specific word in multiple word docs
« Reply #16 on: October 11, 2009, 07:44:36 AM »
To All:

Good Job.
« Last Edit: October 12, 2009, 11:09:53 AM by billrich »

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Bat or VBS file to count a specific word in multiple word docs
« Reply #17 on: October 11, 2009, 09:10:26 AM »
You have no idea what your talking about and therefore I suggest you STFU.

Quote
To not show the output of your code is a red flag that your code does not work.

No. It isn't. for a word document I tested, the output was 4. Was that somehow proof that it does work? No.

However people who try to edit the scripts given and then complain when the EDITED script doesn't work, and when it does work they complain about the output in some pedantic fashion... that is a red flag that they have no idea what they are talking about.


In fact the more I think about it the more I think you may have taken lessons from spectateswamp.

I was trying to dereference Null Pointers before it was cool.

Salmon Trout

  • Guest
Re: Bat or VBS file to count a specific word in multiple word docs
« Reply #18 on: October 11, 2009, 10:09:26 AM »
BC_P, having crossed swords with Billrich myself, I can only sympathetically suggest you do what I do, which is basically ignore the bugger. I won't bother trying to correct his "code" any longer. If his half baked outpourings are all that the original poster ends up seeing, well, sadly, so be it. Life's too short.

"BC Hat" indeed!  :)

Is that near Medicine Hat? (No I checked, it's in AB)






billrich

  • Guest
Re: Bat or VBS file to count a specific word in multiple word docs
« Reply #19 on: October 11, 2009, 11:18:38 AM »
Way to go Computer Hope crew.
« Last Edit: October 12, 2009, 11:06:19 AM by billrich »

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Bat or VBS file to count a specific word in multiple word docs
« Reply #20 on: October 11, 2009, 12:22:32 PM »

Point to one post in this thread that helped Petreli, the original poster or anyone who might have read this Thread .
"Bat or VBS file to count a specific word in multiple word docs?"

The Fishman, Mr. Trout, does not have answer?

Ghostdogs Script counts a specific word in multiple word docs. For some reason I believe that qualifies.

here's a full version, searches recursively from current directory. No need batch ... :)
Code: [Select]
Set objFS=CreateObject("Scripting.FileSystemObject")
strFolder="c:\test"
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
  If objDIR <> "\System Volume Information" Then
    For Each eFolder in objDIR.SubFolders
      Go eFolder
    Next
For Each strFile In objDIR.Files
If objFS.GetExtensionName(strFile) = "doc" Then
Set x = CreateObject("Word.Application")
docfile = strFile.Path
countof = 0
    For Each y In x.Documents.Add(docfile).Words
        strword = Trim(Replace(y.Text, vbCrLf, ""))
        If StrComp(strword, "Word", 1) = 0 Then
            countof = countof + 1       
        End If
    Next
    x.Quit
    Set x = Nothing         
    WScript.echo countof , docfile
End If
Next
  End If
End Sub

I was trying to dereference Null Pointers before it was cool.

billrich

  • Guest
Re: Bat or VBS file to count a specific word in multiple word docs
« Reply #21 on: October 11, 2009, 01:25:30 PM »
Good Job; Great help by all.
« Last Edit: October 12, 2009, 11:04:34 AM by billrich »