Home / Microsoft / Microsoft DOS / This is Bug in .bat file?
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: 1 [2] 3  All - (Bottom) Print
Author Topic: This is Bug in .bat file?  (Read 2062 times)
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,365

Computer: Specs
Experience: Guru
OS: Linux variant

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


IP logged

gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« 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?
IP logged

gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« 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?
IP logged

Salmon Trout
Prodigy



Thanked: 501
Posts: 7,365

Computer: Specs
Experience: Guru
OS: Linux variant

1
« 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.
IP logged

Star-Fire
Topic Starter
Rookie



Posts: 13




« 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?  ???
IP logged

I'm bad English
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,365

Computer: Specs
Experience: Guru
OS: Linux variant

1
« 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
IP logged

Star-Fire
Topic Starter
Rookie



Posts: 13




« 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 >_<
IP logged

I'm bad English
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,365

Computer: Specs
Experience: Guru
OS: Linux variant

1
« 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.
IP logged

Star-Fire
Topic Starter
Rookie



Posts: 13




« 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 » IP logged

I'm bad English
gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« Reply #24 on: November 01, 2009, 11:33:59 PM »

see post #20 again !!!!
IP logged

Star-Fire
Topic Starter
Rookie



Posts: 13




« 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
IP logged

I'm bad English
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,365

Computer: Specs
Experience: Guru
OS: Linux variant

1
« 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.
IP logged

Star-Fire
Topic Starter
Rookie



Posts: 13




« 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
IP logged

I'm bad English
BC_Programmer
Mastermind


Thanked: 682
Posts: 15,624

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #28 on: November 03, 2009, 04:02:30 AM »

use cscript.exe not wscript.exe to interpret the file.
IP logged

gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« 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.
IP logged

Pages: 1 [2] 3  All - (Top) Print 
Home / Microsoft / Microsoft DOS / This is Bug in .bat file? « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.103 seconds with 21 queries.