1、以下代码可以建立多级文件夹:
Option Explicit
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
'创建指定的目录(可以是多级目录)
Private Function CreateDirectory(ByVal sDirectory As String) As Boolean
'创建指定的目录(可以是多级目录),sDirectory:要创建的文件夹
On Error GoTo ErrHandle
Dim lngResult As Long
sDirectory = checkpath(sDirectory)
lngResult = MakeSureDirectoryPathExists(sDirectory)
CreateDirectory = IIf(lngResult = 0, False, True)
ErrHandle:
If Err <> 0 Then
CreateDirectory = False
End If
End Function
Private Function checkpath(ByVal sPath As String) As String
If Right$(sPath, 1) = "/" Then
checkpath = sPath
Else
checkpath = sPath & "/"
End If
End Function
Private Sub Command1_Click()
CreateDirectory "c:/abc/def/ghi"
End Sub
2、主要是文件的“打开”、“读取”、“保存”,多练习一下。
创建新文件和在文件增加
Open "D:/xxx.txt for append As #1
Print #1,"1234"
Print #1,"ABCD"
Close #1
'append 是以追加的方式操作的 还可以换成input,output等等 比如
文件已经存在时:
Open "D:/xxx.txt for input As #1
do while not eof(1)
input #1,a
...
loop
Close #1
'上面的是打开和读取
3、一个判断
If Dir("c:/test.txt") = "" Then
MsgBox "指定文件不存在"
Else
MsgBox "指定文件存在"
End If