在管理公私文件時(shí)總是喜歡隨處亂放,找尋起來(lái)只能利用Microsoft的搜索功能了,而有時(shí)因?yàn)橥浟宋募踔琳叶颊也坏?,那種強(qiáng)迫感很恐怖的。
首先看一下結(jié)果:
程序幫助調(diào)取了指定文件夾下面所有的文件名、文件后綴、文件路徑、文件夾名等等,如果您也寫(xiě)過(guò)VBA程序,那么相信還會(huì)發(fā)揮您的所長(zhǎng)加入文件大小、文件創(chuàng)建日期等等屬性豐富這個(gè)程序的。
這個(gè)程序涉及了4個(gè)子程序:
- jove_loop_total: 總程序
- jove_loop_step1:清楚原有格式、加入標(biāo)題行并調(diào)用下一個(gè)程序
- OkExcel(sPath As String):讀取文件與文件夾信息
- jove_loop_step2:循環(huán)讀取文件夾屬性的那些字段,并讀取其內(nèi)部的文件們 --- 類似蜘蛛爬
宏程序源碼:
Sub jove_loop_total() 'D盤(pán)下全部文件夾及文件讀取用插件 Call jove_loop_step1 Call jove_loop_step2 MsgBox "Done"
End Sub
Sub jove_loop_step1()
'加上標(biāo)題行 Columns("A:C").Clear Cells(1, 1) = "文件名" Cells(1, 2) = "類型" Cells(1, 3) = "所在位置" Dim jove_address As String jove_address = ThisWorkbook.Path Call OkExcel(jove_address & "")
End Sub Sub OkExcel(sPath As String)
Dim i As Long Dim sTxt As String
i = Range("A65535").End(xlUp).Row sTxt = Dir(sPath, 31) Do While sTxt <> "" On Error Resume Next If sTxt <> ThisWorkbook.Name And sTxt <> "." And sTxt <> ".." And sTxt <> "081226" Then '忽略哪些隱藏系統(tǒng)文件夾 i = i + 1 Cells(i, 1) = "'" & sTxt If (GetAttr(sPath & sTxt) And vbDirectory) = vbDirectory Then '如果是文件夾 Cells(i, 2) = "文件夾" Cells(i, 3) = sPath & sTxt & "" Cells(i, 1).Hyperlinks.Add Anchor:=Selection, Address:=Cells(i, 3) Else '如果是文件 Cells(i, 2) = "文件" Cells(i, 3) = sPath & sTxt Cells(i, 1).Hyperlinks.Add Anchor:=Selection, Address:=Cells(i, 3) End If End If sTxt = Dir Loop End Sub
Sub jove_loop_step2()
For i = 2 To 65535 On Error Resume Next If Cells(i, 2) = "文件夾" And Cells(i, 1) <> "Foxmail" And Cells(i, 1) <> "RECYCLER" And Cells(i, 1) <> "System Volume Information" And Cells(i, 1) <> "mail" Then '忽略哪些隱藏系統(tǒng)文件夾 Call OkExcel(Cells(i, 3)) End If
Next
End Sub
|