2番目の質問「ワイルドカードを使用して検索するリンクのコードを変更するにはどうすればよいですか」に答えるには問題のコードはサブルーチンです:
Sub FindFile(searchname, searchdir) ' Two parameters: file name, search directory
On Error Resume Next ' Enable error handling so we don't crash out on access denied errors
Dim file, folder, subfolder
For Each file In fso.GetFolder(searchdir).Files ' Process each file (as a file object) in the search directory
If LCase(searchname) = LCase(file.Name) Then ' See if file name matches. Using LCase to convert both to lowercase for case insensitivity.
ReDim Preserve fileslist(UBound(fileslist) + 1) ' If match found then increase array size by 1
fileslist(UBound(fileslist)) = file.Path ' Store the file path in newly added array entry
End If
Next
' Now the recursive bit. For any subfolders in current search directory, call FindFile again
' with (1) the same file name originally passed in as "searchname", and (2) a new search
' directory of the subfolder's name. FindFile then starts again on this new directory: finds files,
' adds matches to the fileslist array, then does the same on each subfolder found. This
' is how it searches each subfolder (and subfolders of subfolders... etc) in a directory
For Each subfolder In fso.GetFolder(searchdir).SubFolders
FindFile searchname, subfolder.Path
Next
On Error GoTo 0
End Sub
ここで重要なのビットがラインIf LCase(searchname) = LCase(file.Name) Then
です。 searchname
は、ワイルドカード型の検索として働き、文字列file.name
、中に含まれている場合はtrueを返します
If instr(1,LCase(file.Name), LCase(searchname)) Then
:私たちは、これを変更することができます。
次の行:名前だけではなく、パスを取得するために
fileslist(UBound(fileslist)) = file.Name
:
fileslist(UBound(fileslist)) = file.Path
に変更することでした。
私はこれが広すぎると思います。これのどの部分に問題がありますか? vbscriptでユーザー入力を取得しますか?ワイルドカードを使用してコンピュータ上のファイルを検索しますか?検索で見つかったファイル名の配列から結果を表示しますか?すべて一緒に、それは少しです。 – JNevill
私は「あまりにも広すぎる」と少し混乱していますが、私は簡単な質問をしなければならないと思います。参照された質問/回答でVBスクリプトをどのように取って、キーワード?たとえば、 'file.nameと等しい'を 'file.name'のように変更できますか? – random13
質問が実際には3つの質問のように聞こえるので、私はそれが広すぎることを示唆しています。 1ユーザー入力を取得する方法(またはユーザー入力を取得する方法)2ワイルドカードを使用してコンピュータ上のファイルを検索する方法3ファイル名のみが返されるように結果を解析する方法。あなたのリンクの質問はもっと広範で、答えがあるので、それは疑問ではないと思います。 – JNevill