
vb新手提问关于文件夹关键字搜索和删除的问题,高分悬赏求解答!
我想实现以下功能:按下Command1的时候,搜索d:\123目录下以abc开头的文件夹(如abc1111、abc1112、abc1113有很多这样的),再搜索d:\12...
我想实现以下功能:
按下Command1的时候,搜索d:\123目录下以abc开头的文件夹(如abc1111、abc1112、 abc1113有很多这样的),再搜索d:\123这个目录下以hehe开头的blob扩展名的文件(如hehe_1_2.blob、 hehe_2_3.blob),再统计以abc开头的文件夹们和hehe开头的blob文件们的总大小,显示在label1里,此时再点击一次 command1,就删除这些东西。
如果没有源码的话提供一下思路也行啊!多谢了! 展开
按下Command1的时候,搜索d:\123目录下以abc开头的文件夹(如abc1111、abc1112、 abc1113有很多这样的),再搜索d:\123这个目录下以hehe开头的blob扩展名的文件(如hehe_1_2.blob、 hehe_2_3.blob),再统计以abc开头的文件夹们和hehe开头的blob文件们的总大小,显示在label1里,此时再点击一次 command1,就删除这些东西。
如果没有源码的话提供一下思路也行啊!多谢了! 展开
2个回答
展开全部
'工程引用:Mirosoft Scripting Runtime
Dim DEL As Boolean
Sub Command1_Click()
Dim fso As FileSystemObject
Dim fds As Folders
Dim fd As Folder
Dim fs As Files
Dim f As File
Dim sum As Double
Set fso = CreateObject("Scripting.FileSystemObject")
Set fds = fso.GetFolder("D:\123").SubFolders
Set fs = fso.GetFolder("D:\123").Files
If DEL = False Then
For Each fd In fds
If Left(fd.ShortName, 3) = "abc" Then
sum = sum + fd.Size
End If
Next
For Each f In fs
If Left(f.ShortName, 4) = "hehe" And Right(f.ShortName, 5) = ".blob" Then
sum = sum + f.Size
End If
Next
label1.Caption = sum
Else
For Each fd In fds
If InStr(fd.ShortName, "abc") > 0 Then
fd.Delete True
End If
Next
For Each f In fs
If Left(f.ShortName, 4) = "hehe" And Right(f.ShortName, 5) = ".blob" Then
f.Delete True
End If
Next
End If
End Sub
Dim DEL As Boolean
Sub Command1_Click()
Dim fso As FileSystemObject
Dim fds As Folders
Dim fd As Folder
Dim fs As Files
Dim f As File
Dim sum As Double
Set fso = CreateObject("Scripting.FileSystemObject")
Set fds = fso.GetFolder("D:\123").SubFolders
Set fs = fso.GetFolder("D:\123").Files
If DEL = False Then
For Each fd In fds
If Left(fd.ShortName, 3) = "abc" Then
sum = sum + fd.Size
End If
Next
For Each f In fs
If Left(f.ShortName, 4) = "hehe" And Right(f.ShortName, 5) = ".blob" Then
sum = sum + f.Size
End If
Next
label1.Caption = sum
Else
For Each fd In fds
If InStr(fd.ShortName, "abc") > 0 Then
fd.Delete True
End If
Next
For Each f In fs
If Left(f.ShortName, 4) = "hehe" And Right(f.ShortName, 5) = ".blob" Then
f.Delete True
End If
Next
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询