发布网友 发布时间:2022-04-26 07:43
共3个回答
热心网友 时间:2022-06-25 10:43
Private Sub Command1_Click()
'本程序具有删除功能,不可恢复,慎重
'本程序只保留一个最后的子文件夹。
'On Error Resume Next
Dim fso, sPath As String
Dim myFolder, curFolder
Dim strPath As String, dteCreate As Date
Const MY_COMPUTER = &H11&
Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path
Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "选择你要搜索的文件夹:", OPTIONS, strPath)
If objFolder Is Nothing Then
MsgBox "您没有选择任何有效目录!"
Exit Sub
Else
Set objFolderItem = objFolder.Self
sPath = objFolderItem.Path
Set fso = CreateObject("scripting.filesystemobject")
Set curFolders = fso.GetFolder(sPath)
dteCreate = "1900-1-1"'如果需要只删除最早文件夹,这里改为dteCreate =now
If curFolders.subfolders.Count > 1 Then
For Each myFolder In curFolders.subfolders
Debug.Print sPath & IIf(Len(sPath) = 3, "", "\") & myFolder.Name, myFolder.DateCreated
If dteCreate < myFolder.DateCreated Then'如果需要只删除最早文件夹,这里改为>号
strPath = sPath & IIf(Len(sPath) = 3, "", "\") & myFolder.Name
dteCreate = myFolder.DateCreated
End If
Next
MsgBox strPath & "创建最晚,创建时间" & dteCreate & vbCrLf & "下面删除较早的文件夹"
For Each myFolder In curFolders.subfolders
If dteCreate <> myFolder.DateCreated And strPath <> sPath & IIf(Len(sPath) = 3, "", "\") & myFolder.Name Then'如果需要只删除最早文件夹,这里把<>改为=
'myFolder.Delete True'本行具有删除功能,不可恢复,慎重
End If
Next
End If
Set fso = Nothing
End If
End Sub
热心网友 时间:2022-06-25 10:44
用shell "cmd dir c:\ /od >" & app.path & "\aa.txt"
之后用读取文本的方式
热心网友 时间:2022-06-25 10:44
参考 FindNext 语句。