/*
デレクトリの再帰検索を行う
dir → 検索ディレクトリ
fukasa → 最大深さ。0ならサブディレクトリを検索しない
callback_func → 検索結果のファイル、フォルダの名前を返す関数のアドレス
返り血 なし
*/
Sub hxtree(dir As *Byte, fukasa As DWord, callback_func As *Sub(p As *Byte))
Dim wfd As WIN32_FIND_DATA
Dim hF As HANDLE
Dim noah[428] As Byte
wsprintf(noah, "%s\*.*", dir)
hF = FindFirstFile(noah, wfd)
Do
If lstrcmp(".", wfd.cFileName) = 0 or lstrcmp("..", wfd.cFileName) = 0 Then *JUMP
wsprintf(noah, "%s\%s", dir,wfd.cFileName)
If callback_func Then callback_func(noah)
If wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY Then
If fukasa Then hxtree(noah, fukasa-1, callback_func)
End If
*JUMP
Loop While FindNextFile(hF, wfd)
FindClose(hF)
End Sub
#console
Sub Out(p As *Byte)
Print MakeStr(p)
End Sub
hxtree("C:\perl", 1, AddressOf(Out))
実行結果
hxtree("C:\perl", 0, AddressOf(Out))
↓
C:\perl\bin
C:\perl\eg
C:\perl\etc
C:\perl\html
C:\perl\lib
C:\perl\site
hxtree("C:\perl", 1, AddressOf(Out))
↓
C:\perl\bin
C:\perl\bin\a2p.exe
C:\perl\bin\ap-update-html
C:\perl\bin\ap-update-html.bat
C:\perl\bin\ap-user-guide
C:\perl\bin\xsubpp.bat
(以下略)
最終更新:2010年02月21日 16:07