我有一个完整的目录列表,我想循环遍历这些目录并打开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文件。任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
而不是:
wscript.echo strLine
你需要这样做:
text = objFSO.OpenTextFile(strLine, ForReading).ReadAll
但是,这会在每次迭代时覆盖变量text
的内容,因此您需要决定是否要将所有文件的文本转换为单个变量(附加从文件中读取的文本)到变量)或单独的变量(将每个文件读入数组的单独字段或类似的东西)。