0

ディレクトリでいっぱいのリストがあり、それらのディレクトリをループして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

コードの問題は、ディレクトリに移動してtest.txtファイルを読み取るのではなく、folders.txtのデータを読み取ることです。誰でもこれを修正するのを手伝ってもらえますか?

4

1 に答える 1

0

これの代わりに:

wscript.echo strLine

これを行う必要があります:

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

ただし、これは反復ごとに変数の内容を上書きするtextため、すべてのファイルのテキストを単一の変数に入れる (ファイルから読み取ったテキストを変数に追加する) か、別の変数に入れるかを決定する必要があります。 (各ファイルを配列の個別のフィールドまたはそのようなものに読み取ります)。

于 2012-10-29T20:34:16.190 に答える