在VB中,可以使用dir函数来判断文件夹是否存在,可使用MkDir来创建一个新目录,以下是一个简单的示例,通过示例代码你会对dir的用法有所熟悉:
VB判断文件夹是否存在,若不存在则自动创建一个目录: If Dir( "D:\temp" ,vbDirectory) = "" Then MkDir "D:\temp"
End If
If Dir( "D:\temp\test.txt" ) = "" Then
msgbox "文件D:\temp\test.txt不存在" end if 我们还可以用FSO来实现:
dim fso as filesystemobject
set fso=new filesystemobject
If fso.FolderExists( "D:\temp" ) Then
MsgBox "D:\temp存在!"
Else
fso.CreateFolder ( "D:\temp" )
End If |
|
|
|
|
|
|
|
|
|