0

テキスト ファイルのリストを開き、その内容のパターンを見つけて、そのパターンに従って他のフォルダーに移動する必要があるプロジェクトについて、助けが必要です。

たとえば、テキスト ファイルのリストで、"blue" という単語が含まれているファイルを見つけて、それらだけを "Blue" という名前の別のフォルダーに移動する必要があります。

コマンド FileSystemObject を使用して実行しようとしていましたが、ちょっと迷ってしまいました。

よろしくお願いします!

4

1 に答える 1

1
Dim sDir As String
Dim sPath As String
Dim sPattern as String
Dim sReadedData as String
dim sDestiny as string
dim sPathDestiny as string
Dim fso As Object

Set fso = VBA.CreateObject("Scripting.FileSystemObject")

sPath$ = "c:\YourFolder"
sDir$ = Dir(sPath, vbDirectory)
sPattern= "abcdefg"
sDestiny="c:\DestinyFolder"

If sDir = "" Then
MsgBox "Path " & sDir & " Not Found"
End
End If
sDir$ = Dir(sPath & "\*.txt")
Do Until sDir = ""
     sPathDestiny=Replace(sDir, sPath, sDestiny)
     Open sDir$ For Input As #1
     do until EOF(1)   
         Input #1, sReadedData
     loop
     if InStr(sReadedData, sPattern)>0 then
         Call fso.CopyFile(sDir, sPathDestiny)
     end if
Loop

これが主なアイデアです。それで遊びます。

于 2015-09-11T12:01:06.693 に答える