Count of files in all subfolders

User avatar
Abraxus
3StarLounger
Posts: 254
Joined: 01 Mar 2010, 17:34
Location: Blue Springs, MO

Count of files in all subfolders

Post by Abraxus »

I have a folder that contains SO SO many subfolders which contain SO SO many subfolders with can contain 1 to many files.

We are moving it from an online repository to another, so it is being downloaded to my computer and I need to validate that we have them all.

Anyone have some code that can be passed the root directory and then provide me a list of folders and subfolders along with the count of files (of any type)?

Thanks!
Morgan

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: Cound of files in all subfolders

Post by SpeakEasy »

Have you considered Powershell?

e.g

List
Dir -Path d:\nameof\rootfolder -recurse -file | format-table -property Directory, Name

Count
dir -Path d:\downloads\deleteme -recurse -file | measure-object | select-object -Property Count
Last edited by SpeakEasy on 04 Aug 2023, 10:17, edited 1 time in total.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15640
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Count of files in all subfolders

Post by ChrisGreaves »

Abraxus wrote:
03 Aug 2023, 19:14
We are moving it from an online repository to another, so it is being downloaded to my computer and I need to validate that we have them all.
Hi Abraxus, I do not have a firm answer, but am confident that Everything 1.5a can do this. Problem is I don't know Everything 1.5a well enough to suggest the search string!
In your Copious Free you might wade through this 4-year-old topic "Question: Comparing drives/folders for files"

Everything has search functions such as Unique: and extensive Dupe: functionality and, perhaps relevant to your case, logical-NOT operators.
On top of that you can create EFU lists (of files on a volume) and then compare the two list to report non-duplicates.

Bottom line: try posting your question at VoidTools forums and let their experts have a shot at it.

I began with this Advanced Search.

Truly, I hope that this leads you forward.
Cheers, Chris
He who plants a seed, plants life.

robertocm
Lounger
Posts: 43
Joined: 07 Jun 2023, 15:34

Re: Count of files in all subfolders

Post by robertocm »

Code example:
Libro1.xlsm
Reference:
https://stackoverflow.com/questions/103 ... -using-vba

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: Count of files in all subfolders

Post by SpeakEasy »

Also have you considered Robocopy?

snb
4StarLounger
Posts: 584
Joined: 14 Nov 2012, 16:06

Re: Count of files in all subfolders

Post by snb »

I'd suggest:

Code: Select all

Sub M_snb()
   sn = Split(CreateObject("wscript.shell").exec("cmd /c dir C:*.* /b/s").stdout.readall, vbCrLf)
   Sheet1.Cells(1).Resize(UBound(sn)) = Application.Transpose(sn)
End Sub
More details on directories, filedates, etc; no 64k limitation of application.transpose

Code: Select all

Sub M_snb()
   With CreateObject("New:{8BD21D20-EC42-11CE-9E0D-00AA006002F3}")
      .List = Split(CreateObject("wscript.shell").exec("cmd /c dir G:\*.* /s").stdout.readall, vbCrLf)
       Sheet1.Cells(1).Resize(.ListCount) = .List
    End With
End Sub