Silverfrost Forums

Welcome to our forums

Finding the number of files/folders in a folder

24 Sep 2022 2:11 #29370

Is there a way to find the actual number of files/folders that exist in a folder?

I'm using files@ with a wildcard of . to process file options. It would be helpful is there was a way to determine the number of files/folders that the wildcard would return so the ALLOCATE's I'm doing would get the full measure!

A single function would be very easy to implement. Failing that, a function similar to get_multiple_filenames@() would be useful in achieving the ultimate goal.

24 Sep 2022 3:13 #29371

Bill,

It's probably worth looking at the routine FILES@ (see the FTN77 Library Reference file in Silverfrost > Silverfrost Fortran FTN95: Documentation). Hint: it's on page 33 of the documentation.

Eddie

24 Sep 2022 4:30 #29372

Eddie, that's the function I'm using. The note is that you give it the maximum number to be stored (as KIND=2), then it tells you how many you got. What I'm looking for is knowing how many to ask for, then allocating the data, then using FILES@() to get those files.

In some of the user's folders, I've seen as many as 15000 files.

They may have more.

I could allocate for the maximum size (32767), and may do that if an alternative is not available. This KIND=2 limit is a hold-back to an earlier day of FAT16 (512 files in a folder max) that with today's OS can be exceeded. Even with FAT32, the limit is 65534!

Granted, pathological, but some users don't like to use folders and separate their data.

Thanks for your comment, though. It got me to look deeper into the function and limits, and I learned something today!!

24 Sep 2022 5:27 #29373

Bill,

You could always go through the alphabet, asking for how many files start with A, B, C etc and add the results.

NTFS has a very big limit on the number of files.

Eddie

24 Sep 2022 5:31 #29374

Try pointing at C:\Windows\WinSxS

24 Sep 2022 7:12 #29375

Robert, yeah, only 14000 files on my system. A good test set, though!

25 Sep 2022 7:11 #29376

There is an undocumented function for this.

program main
use clrwin
integer n
n = count_files@('C:\techsupport')
print*, n
end program

I will add this to the documentation.

27 Sep 2022 6:37 #29388

I use FILES@ and FILES8@ for scanning tree directories.

I use an array to store all the information, appending to the work array. The array can be larger than 32767, but only the next 32767 can be provided to FILES@ for each directory.

I have been using FILES8@ for years to scan a disk for recent files etc ( my NSIZE utility), especially for the files changed in the last week when doing timesheets !

I would be happy to provide a link to my latest win-32 version. ( I don't think I have converted this to /64, as there are a few integer*2 constraints.

C:\Windows\WinSxS is interesting !

https://www.dropbox.com/s/pa16n669iet7fdk/nsize_13.zip?dl=0

try 'nsize /?' for some help, or 'nsize /-d' to dump out all files in the current tree, or 'nsize c:\ /si 010922 /-d' for all files on teh c: drive that have changed since 1-Sep-22

This is my go to utility to find lost files or projects.

Please login to reply.