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

Author Topic: This is Bug in .bat file?  (Read 11424 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: This is Bug in .bat file?
« Reply #15 on: October 18, 2009, 03:23:08 AM »
I wonder, gh0std0g74, if you have tested your (as posted) vbs solution?

for the record...

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   
  End If
For Each strFile In objDIR.Files
name =strFile.Name
If objFS.GetExtensionName(strFile) = "txt" Then
Set objFile = objFS.OpenTextFile(name)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
WScript.Echo Mid(strLine,1,30)
Loop
    Set objFile = Nothing         
End If
Next
End Sub



gh0std0g74



    Apprentice

    Thanked: 37
    Re: This is Bug in .bat file?
    « Reply #16 on: October 18, 2009, 05:06:05 AM »
    Cscript is invoked ***once*** for each line of each text file.
    yes...that's my point.. thanks for clarifying my bad english. If each text file has 3000 lines and there are 10 such files for example,  then cscript is invoked 3000*10 times.... am i correct to say that?

    gh0std0g74



      Apprentice

      Thanked: 37
      Re: This is Bug in .bat file?
      « Reply #17 on: October 18, 2009, 05:10:51 AM »
      I wonder, gh0std0g74, if you have tested your vbs solution?
      and i wonder why you think i didn't
      Code: [Select]
      C:\test>more test.vbs
      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
        End If
              For Each strFile In objDIR.Files
                      name =strFile.Name
                      If objFS.GetExtensionName(strFile) = "txt" Then
                              Set objFile = objFS.OpenTextFile(name)
                              Do Until objFile.AtEndOfStream
                                      strLine = objFile.ReadLine
                                      WScript.Echo Mid(strLine,1,10)
                              Loop
                          Set objFile = Nothing
                      End If
              Next
      End Sub
      C:\test>more file.txt
      file.txt line one
      file.txt line two

      C:\test>more file1.txt
      file1.txt line one
      file1.txt line two

      C:\test>more file2.txt
      file2.txt line one
      file2.txt line two

      C:\test>cscript /nologo test.vbs
      file.txt l
      file.txt l
      file1.txt
      file1.txt
      file2.txt
      file2.txt

      so what's your nitpick all about?

      Salmon Trout

      • Guest
      Re: This is Bug in .bat file?
      « Reply #18 on: October 18, 2009, 05:23:53 AM »
      and i wonder why you think i didn't

      My mistake; I assumed that since you hard coded the folder name, I could run it from anywhere, but in fact it only works when run from inside the folder.

      Star-Fire

        Topic Starter


        Rookie
        Re: This is Bug in .bat file?
        « Reply #19 on: October 22, 2009, 09:39:37 AM »
        Quote
        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
          End If
                For Each strFile In objDIR.Files
                        name =strFile.Name
                        If objFS.GetExtensionName(strFile) = "txt" Then
                                Set objFile = objFS.OpenTextFile(name)
                                Do Until objFile.AtEndOfStream
                                        strLine = objFile.ReadLine
                                        WScript.Echo Mid(strLine,1,10)
                                Loop
                            Set objFile = Nothing
                        End If
                Next
        End Sub
        How i can save all line to one file?  ???
        I'm bad English

        Salmon Trout

        • Guest
        Re: This is Bug in .bat file?
        « Reply #20 on: October 22, 2009, 11:59:04 AM »
        How i can save all line to one file?  ???

        Code: [Select]
        cscript //nologo scriptname.vbs > file.txt

        Star-Fire

          Topic Starter


          Rookie
          Re: This is Bug in .bat file?
          « Reply #21 on: October 27, 2009, 02:37:42 AM »
          Sorry,
           I want say, how i can create output when run this code:
          Quote
          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
            End If
                  For Each strFile In objDIR.Files
                          name =strFile.Name
                          If objFS.GetExtensionName(strFile) = "txt" Then
                                  Set objFile = objFS.OpenTextFile(name)
                                  Do Until objFile.AtEndOfStream
                                          strLine = objFile.ReadLine
                                          WScript.Echo Mid(strLine,1,10)
                                  Loop
                              Set objFile = Nothing
                          End If
                  Next
          End Sub
          I don't know vbs >_<
          I'm bad English

          Salmon Trout

          • Guest
          Re: This is Bug in .bat file?
          « Reply #22 on: October 27, 2009, 02:46:20 AM »
          1. Save the script with a .vbs extension
          2. Run it as I showed you.

          Star-Fire

            Topic Starter


            Rookie
            Re: This is Bug in .bat file?
            « Reply #23 on: November 01, 2009, 11:26:37 PM »
            I have save all your code in file vbs and run it. Program run and print each line on each window and don't create output file.

            Quote
            Set objFS=CreateObject("Scripting.FileSystemObject")
            strFolder = "G:\AH\aa"
            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
              End If
                    For Each strFile In objDIR.Files
                            name =strFile.Name
                            If objFS.GetExtensionName(strFile) = "txt" Then
                                    Set objFile = objFS.OpenTextFile(name)
                                    Do Until objFile.AtEndOfStream
                                            strLine = objFile.ReadLine
                                            WScript.Echo Mid(strLine,1,10)
                                    Loop
                                Set objFile = Nothing
                            End If
                    Next
            End Sub
            "G:\AH\aa" it my path and folder "aa" have many file txt.

             My "Scripting Host" error?
            « Last Edit: November 01, 2009, 11:36:48 PM by Star-Fire »
            I'm bad English

            gh0std0g74



              Apprentice

              Thanked: 37
              Re: This is Bug in .bat file?
              « Reply #24 on: November 01, 2009, 11:33:59 PM »
              see post #20 again !!!!

              Star-Fire

                Topic Starter


                Rookie
                Re: This is Bug in .bat file?
                « Reply #25 on: November 01, 2009, 11:52:54 PM »
                Thanks your help.
                 I need use
                Quote
                cscript //nologo scriptname.vbs > file.txt

                before run your vbs

                 I have output file, but I don't want it

                Quote
                print each line on each window
                I'm bad English

                Salmon Trout

                • Guest
                Re: This is Bug in .bat file?
                « Reply #26 on: November 02, 2009, 12:44:26 AM »
                Quote
                cscript //nologo scriptname.vbs > file.txt

                Don't type "scriptname.vbs", type the actual name that you saved the script as. After it has finished, load file.txt into an editor such as Notepad so you can see it.

                Star-Fire

                  Topic Starter


                  Rookie
                  Re: This is Bug in .bat file?
                  « Reply #27 on: November 03, 2009, 12:32:01 AM »
                  Quote
                  "scriptname.vbs"
                  I know it is name my script, "WScript.Echo" will print all line when I run script. One window "Window Script host" will open with each line, I need choose "enter" per each (I can't do it with 3000+ line). I want stop it when i have output File
                  I'm bad English

                  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: This is Bug in .bat file?
                  « Reply #28 on: November 03, 2009, 04:02:30 AM »
                  use cscript.exe not wscript.exe to interpret the file.
                  I was trying to dereference Null Pointers before it was cool.

                  gh0std0g74



                    Apprentice

                    Thanked: 37
                    Re: This is Bug in .bat file?
                    « Reply #29 on: November 03, 2009, 04:21:41 AM »
                    use cscript.exe not wscript.exe to interpret the file.
                    its so bizarre. i remember i did use cscript.exe, not wscript.exe.