List S3 Files and Subdirectories

18 次查看(过去 30 天)
Nick
Nick 2023-5-19
评论: Stephane 2024-3-12
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.
  2 个评论
Nick
Nick 2023-5-21
I was never able to get filedatastore or webread to work how I wanted so I ended up using system commands in Matlab after installing AWS CLI locally. Something like:
[status,cmdout] = system(['aws s3 ls s3://[your s3 bucket]']
Stephane
Stephane 2024-3-12
You may want to use matlab.io.datastore.FileSet (https://au.mathworks.com/help/matlab/ref/matlab.io.datastore.fileset.html). This method has a 'IncludeSubfolders',true as argument.

请先登录,再进行评论。

回答(1 个)

Askic V
Askic V 2023-5-19
编辑:Askic V 2023-5-19
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:');
disp(fDatastore.Files);
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.

类别

Help CenterFile Exchange 中查找有关 Big Data Processing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by