« [VB6.0] フォルダ作成・削除 | メイン | [VB6.0] CSVを出力 »

2005年10月13日

[VB6.0] フォルダ内の検索

'例1:

Dim DireFile As String

'検索したいフォルダを指定
DireFile = Dir$(App.Path & "\", vbDirectory) '指定フォルダ内をすべて検索する場合
'DireFile = Dir$(App.Path & "\*.*") '指定フォルダ内のファイルのみ検索する場合

Do While DireFile <> ""
If (GetAttr(App.Path & "\" & DireFile)) And (vbDirectory) = vbDirectory Then
If Right(DireFile, 4) = ".csv" Then
MsgBox "ファイルあり"
End If
End If
DireFile = Dir$
Loop

'例2:フルパスがわかっている場合

Dim FileName As String
FileName = Dir(App.Path) ' & "\Sample.csv")

'ファイルがない場合 FileName=""
If FileName <> "" Then
MsgBox "ファイルあり"
End If

2005 / 10 / 13