vb检查文件是否存在

来源:百度知道 编辑:UC知道 时间:2024/05/05 05:37:29
请问,如果我用VB,想在D盘里创建文件夹名为KK,如果KK存在就创建kk1,如果kk1存在就创建KK2,依此类推..请高手贴出代码...万分感谢~~~~~~~~
那就从kk检查到kk10吧...

嘿嘿,自己写了一个,调试通过:

Private Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As Long

Public Sub Command1_Click()
Dim Path
Dim tPath
Dim i
Path = "d:\kk"
tPath = Path
i = 0
Do While PathFileExists(tPath)
i = i + 1
tPath = Path & i
Loop
If i <> 0 Then Path = Path & i
MkDir Path
MsgBox "创建文件夹“" & Path & "”成功"
End Sub

哦,应该可以的吧,但是不知道有没有极限啊!
肯定有限制的啊!