国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > VBScript > 正文

vbs搜索文件名或者得到目錄列表

2019-10-26 18:00:34
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
'把網(wǎng)上的一個(gè)小程序改得方便了點(diǎn),這個(gè)搜索次效率很好。
復(fù)制代碼 代碼如下:

on error resume next 
Dim keyWord, DirTotal, TimeSpend, FileTotal, Fso, outFile, txtResult, txtPath, sPath  
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 "您沒(méi)有選擇任何有效目錄!" 
   wscript.quit  
else 
Set objFolderItem = objFolder.Self 
sPath = objFolderItem.Path 
txtpath=sPath 
Set Fso = wscript.CreateObject("scripting.filesystemobject")  

FileTotal = 0  
DirTotal = 0  

'sPath = left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName))  
'txtPath = trim(inputbox("你選的目錄是"&sPath,"文件搜索",sPath)) 

keyWord = LCase(inputbox("請(qǐng)輸入搜索關(guān)鍵字點(diǎn)Cancel的話會(huì)得到目錄列表:","文件搜索","mp3"))  

set outFile = Fso.createtextfile(sPath & "/SearchResult.txt")  

outFile.writeline "開(kāi)始搜索..."  
outFile.writeline "起啟目錄:" & txtPath  
TimeSpend = Timer  

myFind txtPath  

TimeSpend = round(Timer - TimeSpend,2)  

txtResult = "搜索完成!" & vbCrLf & "共找到文件:" & FileTotal & "個(gè)." & vbCrLf & "共搜索目錄:" & DirTotal & "個(gè)." & vbCrLf & "用時(shí):" & TimeSpend & "秒."  
outFile.write txtResult  
msgbox txtResult &"結(jié)果保存在"&sPath &"/SearchResult.txt" 

outFile.close  
set outFile = nothing  
set Fso = nothing  

Sub myFind(ByVal thePath)  

Dim fso, myFolder, myFile, curFolder  
Set fso = wscript.CreateObject("scripting.filesystemobject")  
Set curFolders = fso.getfolder(thePath)  
DirTotal = DirTotal + 1  
If curFolders.Files.Count > 0 Then  
For Each myFile In curFolders.Files  
If InStr(1, LCase(myFile.Name), keyWord) > 0 Then  
outFile.WriteLine FormatPath(thePath) & "/" & myFile.Name  
FileTotal = FileTotal + 1  
End If  
Next  
End If  
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 博野县| 弥渡县| 贡山| 全州县| 札达县| 介休市| 华容县| 喀什市| 渭南市| 夏河县| 澎湖县| 平遥县| 江川县| 宝丰县| 五台县| 越西县| 福鼎市| 巍山| 潜江市| 平原县| 安多县| 都昌县| 色达县| 疏勒县| 刚察县| 广元市| 临漳县| 行唐县| 格尔木市| 杂多县| 望城县| 焉耆| 衡阳县| 朔州市| 兴安县| 金沙县| 惠州市| 越西县| 泰和县| 新闻| 茶陵县|