我已经在a和b列中获得了文件名和相应的文件夹。
如何计算每个文件夹和子文件夹中的文件数?
这些是参考文献:
count files in specific folder and display the number into 1 cel
到目前为止,我已完成以下操作
Private Sub SelectFolder_Click()
Call GetAllFolders(x, strPath, objFso, intCountRows)
Call count
End Sub
以下是计数部分
Sub count()
Dim FolderPath As String, path As String, count As Integer
Dim Filename As String
Dim strPath As String
FolderPath = "D:\Users\Desktop\test"
Filename = Dir("")
Do While Filename <> ""
count = count + 1
Filename = Dir()
Loop
Range("C3").Value = count
'MsgBox count & " : files found in folder"
End Sub
如何计算每个文件夹和子文件夹中的文件数?感谢
答案 0 :(得分:1)
GetFileCount将计算目录和目录的子目录中的所有文件。
Range("C3").Value = getFileCount("D:\Users\Desktop\test")
Function getFileCount(localRoot, Optional fld, Optional count As Long) As Long
Dim fso, f, baseFolder, subFolder, ftpFile, i
Set fso = CreateObject("Scripting.Filesystemobject")
If IsMissing(fld) Then
Set baseFolder = fso.GetFolder(localRoot)
Else
Set baseFolder = fld
End If
count = count + baseFolder.Files.count
For Each subFolder In baseFolder.SubFolders
getFileCount localRoot, subFolder, count
Next
getFileCount = count
End Function
答案 1 :(得分:0)
我希望这会有所帮助。我找到了以下代码:
workbook = xlsxwriter.Workbook('app/smth1/smth2/Expenses01.xlsx')
然后我做了一些修改:
filename, _ = QFileDialog.getOpenFileNames(self, 'Select Multi File', 'default', 'All Files (*)')