Obtain the number of files in the folder directly below the drive and the last update date and time

Asked 2 years ago, Updated 2 years ago, 94 views

Suppose you have a folder directly below the drive as shown below.

  • C:\A
  • C:\B
  • C:\C

I would like to aggregate the number of files and the last update date and time on EXCEL for folders A, B, and C just below these drives.
(Not applicable to subfolders in A, B, and C)

Is it possible to do the above?

vba excel batch-file

2022-09-30 14:52

2 Answers

By the way, Excel has a feature called Power Query.This is a proprietary language that retrieves and outputs a variety of data in the form of a table on Excel, so you can achieve the table you want.

Run Data > Retrieve Data > Launch Power Query Editor and
Select Home - New Source - Other Sources - Empty Query and click
Enter the following code in Home > Advanced Editor and
Run Home > Close and Load.

let
    Source = Folder.Contents("C:\"),
    Narrowing = Table.SelectRows (source, each List.Contains({"A", "B", "C"}, [Name]),
    Add File Count = Table.AddColumn (narrowed, "Files Count", each List.Count (List.Select ([Content][Attributes], each [Kind]<"Folder")),
    Column order = Table.SelectColumns (add file count, {"Name", "file count", "Date modified"},
    Column name change = Table.RenameColumns (column order, {{"Name", "Folder Name", {"Date modified", "Last Updated"}}})
in
    column renaming

You should now enter a table similar to the following:

Enter a description of the image here

Data - Update All updates the contents of the table, which rewrites the filename and the date and time of the last update.

Unlike VBA, it doesn't require supporting information such as which cells, what data, and so on, and it's easy to use because it's purely data-processing.


2022-09-30 14:52

vba can be accomplished by using the FileSystemObject.GetFolder method as follows:
Last update date and time is DateLastModified property of


2022-09-30 14:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.