module1.bas
来自「创建文件夹的例子.附带判断,目标有就跳过,没就添加」· BAS 代码 · 共 32 行
BAS
32 行
Attribute VB_Name = "Module1"
Public Function FindFolder(FolderName As String) As Boolean
'查找文件夹,并且在没有的情况下创建文件夹
'创建fso对象模型
' 由于fso对象包含在scripting 类型库 (scrrun.dll)中,所以在使用前首先需要在在工程中引用这个文件,单击“工程”,“引用”,然后在“引用”对话框中选中“microsoft scripting runtime”前的复选框,然后单击“确定”。
Dim fso As New FileSystemObject
Dim file As String
Dim FindHere As Boolean
'file = App.Path & "\" & FolderName
file = "c:\" & FolderName
'FolderExists 函数用来判断文件夹是否存在
FindHere = fso.FolderExists(file)
If FindHere = True Then
'找到文件夹
FindFolder = True
Else
'找到不文件夹
FindFolder = False
End If
'创建文件夹
If FindHere = False Then
fso.CreateFolder (file)
End If
End Function
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?