vb,在一个固定的文件夹A中,每天新加一个以当天日期为文件夹名的文件夹,
答案:2 悬赏:30
解决时间 2021-03-22 12:36
- 提问者网友:✐ۖ﹏ℳ๓北风
- 2021-03-21 21:47
想在来文件夹A中,最多存在3个最新日期文件。如何办,代码是什么?
最佳答案
- 二级知识专家网友:一池湖水
- 2021-03-21 23:23
如:已经存在 D:\A 文件夹,在该文件夹中一当前日期为文件夹名建文件夹.程序如下:
Dim curDir As String '定义文件夹目录名
curDir = "D:\1\" & Format$(Now,"YYYYMMDD") & "\" '以年月日 组成文件夹名称
'判断该文件夹是否存在,不存在就新建
If Len(Dir$(curDir, vbDirectory)) = 0 Then
MkDir curDir
End If
2、如果仅保留 D:\A 目录下以当前日期为最新日期的3个文件夹,其余的都删除
dim curDir As String
dim curPathName
dim curFileName1 As string
dim curFileName2 As string
dim curFileName3 As string
curDir="D:\A\"
curFileName1=curDir & Format$(Date,"YYYYMMDD")
curFileName2=curDir & Format$(DateAdd("d",-1,Date),"YYYYMMDD")
curFileName3=curDir & Format$(DateAdd("d",-2,Date),"YYYYMMDD")
curPathName = Dir(curDir, vbDirectory)
Do While curPathName <> ""
If curPathName <> "." And curPathName <> ".." Then
If (GetAttr(curDir & curPathName) And vbDirectory) = vbDirectory Then
If curPathName <> curFileName1 And curPathName <> curFileName2
And curPathName <> curFileName2 Then
Kill curPathName
End If
End If
End If
curPathName = Dir
Loop
Dim curDir As String '定义文件夹目录名
curDir = "D:\1\" & Format$(Now,"YYYYMMDD") & "\" '以年月日 组成文件夹名称
'判断该文件夹是否存在,不存在就新建
If Len(Dir$(curDir, vbDirectory)) = 0 Then
MkDir curDir
End If
2、如果仅保留 D:\A 目录下以当前日期为最新日期的3个文件夹,其余的都删除
dim curDir As String
dim curPathName
dim curFileName1 As string
dim curFileName2 As string
dim curFileName3 As string
curDir="D:\A\"
curFileName1=curDir & Format$(Date,"YYYYMMDD")
curFileName2=curDir & Format$(DateAdd("d",-1,Date),"YYYYMMDD")
curFileName3=curDir & Format$(DateAdd("d",-2,Date),"YYYYMMDD")
curPathName = Dir(curDir, vbDirectory)
Do While curPathName <> ""
If curPathName <> "." And curPathName <> ".." Then
If (GetAttr(curDir & curPathName) And vbDirectory) = vbDirectory Then
If curPathName <> curFileName1 And curPathName <> curFileName2
And curPathName <> curFileName2 Then
Kill curPathName
End If
End If
End If
curPathName = Dir
Loop
全部回答
- 1楼网友:堕落奶泡
- 2021-03-22 00:41
任务占坑
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯