List S3 Files and Subdirectories
18 views (last 30 days)
I am trying to extract only a list of filenames of a certain extension type (*.nc) from an S3 bucket which includes all subdirectories. All of the fileDatastore examples that I have found seem to load or read the files which is not of interest to me and is slow for very large datasets when all I need is the filename.
If it helps time efficiency, I also know the specific subdirectories of interest within the S3 bucket that I am interested in, although sorting through all of the subdirectories will work too if necessary. If S3 bucket subdirectories are indexable, I would also be interested in implementing some sorting with this information as well.
Askic V on 19 May 2023
Edited: Askic V on 19 May 2023
Well, this small code snippet create a file datastore that include all csv files starting with 'd' or 'D' from the current folder and all subfolders.
Not sure how large your data sets are, but you can give it a try:
% Set the folder path where your files and subfolders are located
folderPath = 'C:\Users\AsV\Documents\Matlab';
% Define the file pattern to match specific file names
filePattern = fullfile(folderPath, '**', 'd*.csv'); % ** includes subfolders
% Create a file data store using the file pattern
fDatastore = fileDatastore(filePattern,'ReadFcn',@readtable,'ReadMode','file');
% Display the files in the data store
disp('Files in the data store:');
In my understanding fileDatasore is specifically created in Matlab to efficiently handle large datasets.
Not really sure how to make it even more efficient in Matlab. Perhaps some other programming language would be a better match.