MSFN Forum: Read txt file line by line (vbscript) - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Read txt file line by line (vbscript) Rate Topic: -----

#1 User is offline   Ruriko 

  • Group: Members
  • Posts: 6
  • Joined: 27-October 12
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 30 October 2012 - 06:50 PM

I am having trouble of making the vbscript to read the text line by line. This is the steps the code should do:

Read folder.txt
Open the file listed in folder.txt
Echo the contents inside of test.txt
Read folder-list.txt
Open the file listed in folder-list.txt
Open dirlist.txt and echo line by line

An example of what folder.txt contains:
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[ Go! Go! Heaven!!]_____________25 -______ ___- [525067]\test.txt
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[12CUT] _____ (Gakkou no Kaidan) [518382]\test.txt
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[2____] _____!__CD__________ [521206]\test.txt
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[Ability] _____________________ [514182]\test.txt


An example of what folder-list.txt contains:
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[ Go! Go! Heaven!!]_____________25 -______ ___- [525067]\dirlist.txt
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[12CUT] _____ (Gakkou no Kaidan) [518382]\dirlist.txt
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[2____] _____!__CD__________ [521206]\dirlist.txt
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[Ability] _____________________ [514182]\dirlist.txt


An example of what each dirlist.txt contains
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[ Go! Go! Heaven!!]_____________25 -______ ___- [525067]\00.jpg
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[ Go! Go! Heaven!!]_____________25 -______ ___- [525067]\a_01.jpg
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[ Go! Go! Heaven!!]_____________25 -______ ___- [525067]\a_02.jpg
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[ Go! Go! Heaven!!]_____________25 -______ ___- [525067]\a_03.jpg


And this is the vbscript code
Option Explicit

Dim objFSO, strTextFile, strData, strLine, arrLines, aniTextFile, aniData, aniLines, meLine, objTextFile, fso, inputFileList, sFolderName, fname
Dim iim1, iret, iret2, iret3, i
CONST ForReading = 1

strTextFile = "C:\Documents and Settings\Administrator\Desktop\ArtistCG\folder.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll
arrLines = Split(strData,vbCrLf)

For Each strLine in arrLines
  strData = objFSO.OpenTextFile(strLine,ForReading).ReadAll
WScript.Echo strData

aniTextFile = "C:\Documents and Settings\Administrator\Desktop\ArtistCG\folder-list.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
aniData = objFSO.OpenTextFile(aniTextFile,ForReading).ReadAll
aniLines = Split(aniData,vbCrLf)

Set fso = CreateObject("Scripting.FileSystemObject")
Set listFile = fso.OpenTextFile(aniLines).ReadAll
do while not listFile.AtEndOfStream 
    fName =  listFile.ReadLine()
    WScript.Echo fName
    Loop
Next

So far I only got steps 1 to 4 working but I can't get it to read dirlist.txt. Any solutions here?


#2 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 30 October 2012 - 09:20 PM

Why are you double posting the same basic question when I provided a VBS script for you in this Thread.

#3 User is offline   Ruriko 

  • Group: Members
  • Posts: 6
  • Joined: 27-October 12
  • OS:Windows 7 x86
  • Country: Country Flag

Posted 31 October 2012 - 03:50 AM

It's not the same but it's similar. The code isn't exactly the same just a bit more code added with more steps. The other thread reads 2 txt file while this one is reading 4 txt files

#4 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,409
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 31 October 2012 - 06:50 AM

View Postgunsmokingman, on 30 October 2012 - 09:20 PM, said:

Why are you double posting the same basic question when I provided a VBS script for you in this Thread.

...and on half the internet... :whistle:
http://www.tek-tips....cfm?qid=1696999
http://www.wjunction...ach-folder.html
http://stackoverflow...e-with-vbscript

jaclaz

#5 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,351
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 31 October 2012 - 11:28 AM

The threads are similir enough for me to issue a warning for double posting, you should of ask for any further
questions in the original thread.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy