前往path&;用vbscript读取txt文件

前往path&;用vbscript读取txt文件,vbscript,Vbscript,我有一个目录列表,我想通过这些目录循环并打开txt文件。然后读取该txt文件中的数据并分配给变量 这是目录列表的一个示例,如下所示: C:\Documents and Settings\Administrator\Desktop\ArtistCG\[ Go! Go! Heaven!!]_____________25 -______ ___- [525067]\test.txt C:\Documents and Settings\Administrator\Desktop\ArtistCG\[12

我有一个目录列表,我想通过这些目录循环并打开txt文件。然后读取该txt文件中的数据并分配给变量

这是目录列表的一个示例,如下所示:

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
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[Abo Manten] Kyuusho seme maniacs vol. 3 (Weak Spot Maniacs vol.3) [521993]\test.txt
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[Afro] Futanari angel cg collection [521560]\test.txt
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[Aim-ZERO] Case Vol.4 [519927]\test.txt
C:\Documents and Settings\Administrator\Desktop\ArtistCG\[Air Hike] ________CG_2 [525114]\test.txt
下面是代码

Option Explicit

Dim objFSO, strTextFile, strData, strLine, arrLines
CONST ForReading = 1

'name of the text file
strTextFile = "C:\Documents and Settings\Administrator\Desktop\ArtistCG\folders.txt"

'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'Step through the lines
For Each strLine in arrLines
wscript.echo strLine
Next

'Cleanup
Set objFSO = Nothing
现在代码的问题是它读取folders.txt的数据,而不是去目录读取test.txt文件。有人能帮我解决这个问题吗?

代替这个:

wscript.echo strLine
您需要这样做:

text = objFSO.OpenTextFile(strLine, ForReading).ReadAll

但是,这会在每次迭代中覆盖变量
text
的内容,因此您需要决定是将所有文件的文本放入单个变量(将从文件读取的文本附加到变量)还是放入单独的变量(将每个文件读入数组的单独字段或类似的内容).

我已经在做了,不是吗?然而,如果你说的“帮我写代码”实际上是指“为我写代码”,答案是否定的。我可以解释你需要做什么,但我希望你自己把它组合起来。那么,您需要将所有文件的内容放在一个变量中,还是将每个内容放在一个单独的变量中?