Computer Hope

Computer Hope Forum Welcome, Guest. Please login or register.
November 22, 2009, 03:06:15 PM
Home Help Staff Chat Login Register
News: Make sure to cast your vote in the November poll.

Computer Hope Forums  >>  Microsoft  >>  Microsoft DOS (Moderator: Computer Hope Admin)  >>  Topic: 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 708 times)
Salmon Trout
Adviser
*
Posts: 960

Thanked: 57
OS: Windows XP
Experience: Guru


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


Logged

Sansovino, Firdaussi, Brown Jack, Lemberg, Woolwinder, and the others... magic names... all gone but for 4472
gh0std0g74
Apprentice
*
Posts: 546

Thanked: 34
OS: Linux Variant
Experience: Experienced


« 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?
Logged

gh0std0g74
Apprentice
*
Posts: 546

Thanked: 34
OS: Linux Variant
Experience: Experienced


« 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:
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?
Logged

Salmon Trout
Adviser
*
Posts: 960

Thanked: 57
OS: Windows XP
Experience: Guru


« 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.
Logged

Sansovino, Firdaussi, Brown Jack, Lemberg, Woolwinder, and the others... magic names... all gone but for 4472
Star-Fire
Topic Starter
Rookie
*
Posts: 13

Thanked: 0
OS: Unknown
Experience: Beginner




« 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?  Huh?
Logged

I'm bad English
Salmon Trout
Adviser
*
Posts: 960

Thanked: 57
OS: Windows XP
Experience: Guru


« Reply #20 on: October 22, 2009, 11:59:04 AM »

How i can save all line to one file?  Huh?

Code:
cscript //nologo scriptname.vbs > file.txt
Logged

Sansovino, Firdaussi, Brown Jack, Lemberg, Woolwinder, and the others... magic names... all gone but for 4472
Star-Fire
Topic Starter
Rookie
*
Posts: 13

Thanked: 0
OS: Unknown
Experience: Beginner




« 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 >_<
Logged

I'm bad English
Salmon Trout
Adviser
*
Posts: 960

Thanked: 57
OS: Windows XP
Experience: Guru


« 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.
Logged

Sansovino, Firdaussi, Brown Jack, Lemberg, Woolwinder, and the others... magic names... all gone but for 4472
Star-Fire
Topic Starter
Rookie
*
Posts: 13

Thanked: 0
OS: Unknown
Experience: Beginner




« 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 » Logged

I'm bad English
gh0std0g74
Apprentice
*
Posts: 546

Thanked: 34
OS: Linux Variant
Experience: Experienced


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

see post #20 again !!!!
Logged

Star-Fire
Topic Starter
Rookie
*
Posts: 13

Thanked: 0
OS: Unknown
Experience: Beginner




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

I'm bad English
Salmon Trout
Adviser
*
Posts: 960

Thanked: 57
OS: Windows XP
Experience: Guru


« 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.
Logged

Sansovino, Firdaussi, Brown Jack, Lemberg, Woolwinder, and the others... magic names... all gone but for 4472
Star-Fire
Topic Starter
Rookie
*
Posts: 13

Thanked: 0
OS: Unknown
Experience: Beginner




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

I'm bad English
BC_Programmer
Sage
*
Posts: 8849

Thanked: 257
OS: Windows XP
Computer: Specs
Experience: Experienced




« Reply #28 on: November 03, 2009, 04:02:30 AM »

use cscript.exe not wscript.exe to interpret the file.
Logged

If this is real life, where the heck is the decimal?
gh0std0g74
Apprentice
*
Posts: 546

Thanked: 34
OS: Linux Variant
Experience: Experienced


« 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.
Logged

Pages: 1 [2] 3  All - (Top) Print 
Computer Hope Forums  >>  Microsoft  >>  Microsoft DOS (Moderator: Computer Hope Admin)  >>  Topic: This is Bug in .bat file? « previous next »
Jump to:  


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright 1998-2008 by Computer Hope (tm). All rights reserved
Powered by SMF 1.1.8 | SMF © 2006-2008, Simple Machines LLC
Page created in 0.094 seconds with 18 queries.