< WSH でショートカットを作成する | ListBox に水平スクロールバーを表示する >

January 31, 2005

MakeSureDirectoryPathExists を VB6 でシミュレートする

VB6 で、MakeSureDirectoryPathExists 関数の動きをシミュレートしたものを作ったので、おいときます。

'******************************************************************
'プロシージャ名:  :MakeSureDirectoryPathExists
'説明:            :SDK に含まれる同名の関数をシミュレートしたもの
'引数:            :pstrDirPath        I   ディレクトリパス
'戻り値           :Boolean型          成否
'******************************************************************
Public Function MakeSureDirectoryPathExists(pstrDirPath As String) As Boolean
'============= Declare ==============
Dim strPathTemp         As String

'============= Initiarize ===========
On Error GoTo MakeSureDirectoryPathExists_E00
    MakeSureDirectoryPathExists = False
'============= Main =================

    strPathTemp = Left$(pstrDirPath, InStrRev(pstrDirPath, "\") - 1&)
    If Len(Dir$(strPathTemp)) Then
        If (GetAttr(strPathTemp) And vbDirectory) Then
            MakeSureDirectoryPathExists = True
        End If
        Exit Function
    End If
    
On Error GoTo MakeSureDirectoryPathExists_E10
    Call MkDir(strPathTemp)
    
'============= Release ==============
MakeSureDirectoryPathExists_L00:
    MakeSureDirectoryPathExists = True
    Exit Function
'============= Error ================
MakeSureDirectoryPathExists_E10:
    If MakeSureDirectoryPathExists(strPathTemp) Then
        Call Err.Clear
        Resume
    End If
MakeSureDirectoryPathExists_E00:
    Call Err.Clear

End Function

千里の道も、一歩から。こつこつためよう、汎用関数。C言語版もなんかのとき作った記憶があるんだけど、思い出せません。

トラックバック

このエントリーにトラックバック:
http://frog.raindrop.jp/cgi-bin/mt/mt-tb.cgi/800

コメント

こんにちはー★★ひろなです★ひろなの学校はもう修学旅行が5月にあったよ★京都、奈良、大阪へ行ったよ(^o^★   質問!! 好きな服のブランドは? 返事待ってます!

コメントする

※ コメントスパム対策のため、コメント本文はおはよう、こんにちわ、こんばんわのいずれかより始めるようにしてください。

name:
email:

※ 必要ですが、表示しません。

url:
情報を保存する ?