VB如何自动创建以日期命名的文件夹,并在文件夹中创建以时间命名的文档?
展开全部
给你一段代码 你自己执行下看下效果吧
Public Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
public function WriteLog(sDesc as string)
Dim sCurrentDate As String
sCurrentDate = Format$(Now, "yyyy-mm-dd hh:mm:ss")
Dim sDir As String, sLogFile As String
sDir = App.Path & "\..\Log\" & Format$(sCurrentDate, "yyyymm")
sLogFile = sDir & "\" & Format$(sCurrentDate, "yyyymmdd") & ".log"
If MakeSureDirectoryPathExists(sLogFile) = 0 Then Exit Function
Dim I As Long
I = FreeFile
Open sFile For Append Access Write As #I
Print #I, sCurrentDate & "`" & sDesc
Close #I
end fucntion
Public Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
public function WriteLog(sDesc as string)
Dim sCurrentDate As String
sCurrentDate = Format$(Now, "yyyy-mm-dd hh:mm:ss")
Dim sDir As String, sLogFile As String
sDir = App.Path & "\..\Log\" & Format$(sCurrentDate, "yyyymm")
sLogFile = sDir & "\" & Format$(sCurrentDate, "yyyymmdd") & ".log"
If MakeSureDirectoryPathExists(sLogFile) = 0 Then Exit Function
Dim I As Long
I = FreeFile
Open sFile For Append Access Write As #I
Print #I, sCurrentDate & "`" & sDesc
Close #I
end fucntion
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim d As String, f As String
d = Format(Now(), "yyyy-mm-dd")
f = Format(Now(), "hh:nn:ss")
MkDir "D:" & "\" & d
'建文件夹
Open "D:" & "\" & d & "\" & f & ".txt" For Output As #1
'建文件
Print #1, "OK"
Close #1
End Sub
Dim d As String, f As String
d = Format(Now(), "yyyy-mm-dd")
f = Format(Now(), "hh:nn:ss")
MkDir "D:" & "\" & d
'建文件夹
Open "D:" & "\" & d & "\" & f & ".txt" For Output As #1
'建文件
Print #1, "OK"
Close #1
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |