『壹』 vb中判斷一個文件夾是否存在
Private Sub Command1_Click()
Dim sFile As String
sFile = IIF(Right$(App.Path,1)="\",App.Path & "一個文件夾\",App.Path & "\" & "一個文件夾\")
sFile = sFile & Trim$(Text3.Text) & ".txt"
Dim FSO As New FileSystemObject
If FSO.FolderExists(sFile) = True Then
MsgBox "此文件夾存在!", vbInformation + vbOKOnly, "提示信息"
Else
MsgBox "此文件夾不存在!", vbInformation + vbOKOnly, "提示信息"
End If
Set FSO = Nothing
End Sub
『貳』 VB 檢查文件(夾)是否存在,創建文件(夾)
If Dir("D:\TP", vbDirectory) = "" Then
MkDir ("D:\TP")
Else
MsgBox "文件夾已存在"
End If
Open "d:\tp\1.txt" For Append As #1 '檢測d:\tp\1.txt是否存在,不存在則創建,存在則打開
Close #1 '關閉1.txt 備註:此處的打開關閉 並不在Windows任務欄顯示
寫完測試過得,放心使用
『叄』 vb中如查找文件是否存在
回答者:墨漬 - 同進士出身 七級 7-10 17:18
正解.不過差一個小參數...文件夾的話就是
if dir("",vbDirectory)
文件就是
if dir("",vbArchive )