Jump to content
Macro Express Forums

how many files in a folder

Recommended Posts

Hi Herbert, and welcome to the forum.


I don't think there is a specific ME Pro command (or option within a command) for achieving that.


If I was doing it, I'd get the macro to open a selected folder's properties and then apply an OCR utility to capture the Size and Number fields.


Or you could do it with a Repeat with Folder loop, counting each file processed.


Another alternative would be to use an AutoIt! script within your macro, as I'm sure that has commands for such basic functions. Maybe one of the AutoIt! experts can amplify?



Terry, East Grinstead, UK

Link to comment
Share on other sites

I don't know an easy, straightforward way to do it.

You could use the Program Launch command to run command.com, passing it a DOS "dir" command and directing output to a text file. For example, dir c:\foldername /s > c:\listfile.txt. Use appropriate options with "dir" if you want to include subfolders.

Then use Text File Begin Process to read back the text file. The last couple lines should tell you number of files and total size, which you can extract into variables. When you get done with this macro you won't consider yourself a newbie any longer.

Link to comment
Share on other sites

You can calculate both the number of files and the total size like this:

Variable Set String %FolderPath% to "e:\Download Files"
Variable Set Integer %SizeOfFiles% to 0 // SizeOfFiles is a Large Integer variable
Variable Set Integer %FileCount% to 0

Repeat with Folder %FolderPath%
 Variable Modify Integer %FileCount%: Increment
 Variable Set From File: Set to the Size of a File (%AFile%) // AFile is a Large Integer variable
 Variable Modify Integer: %SizeOfFiles% = %SizeOfFiles% + %FileSize%
End Repeat

Text Box Display: Results: Size of Folder and Number of Files

A sample macro file is attached.

Sample Size of Foler and Number of Files.mex

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...