vb,在一个固定的文件夹A中,每天新加一个以当天日期为文件夹名的文件夹,
1个回答
展开全部
如:已经存在 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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询