Load Files from folder based on file number

I have 100 csv files in a folder. Each is labeled with a totally random number such as 233505.csv. I need to load 3 specific files. I originally tried
uigetfile('.csv','MultiSelect','on')
This worked but it required me to select the files I want. I am now trying using a datastore function so that I dont need to manually select the files. However I dont think the name-value pair "Filenames" is correct. Is there an alternative method. The Dir function only allows me to specify a single file.
ds = tabularTextDatastore("C:\Users\e\Player","FileExtensions",[".csv"],"Filenames",["233505.csv","45067.csv"]);

3 commentaires

Stephen23
Stephen23 le 22 Nov 2021
"I am now trying using a datastore function so that I dont need to manually select the files"
How will using a DATASTORE achieve that?
The task is unclear: so you have 100 CSV file but only want to process 3 of them and apparently you do not want to use UIGETFILE. So far no problems. However you forgot to tell us the most important information: how do you want to select those 3 files: randomly from all files? randomly from a subset of the files? Always the same 3 files (i.e. a list)? Based on a feature of the filename/filesize/file modification date/whatever other file meta-data you might care about? Based on user input (but not UIGETFILE)?
Are we supposed to guess how you want to select those 3 files?
Doron Joffe
Doron Joffe le 22 Nov 2021
Thank you. I want to select them based on a feature of the file name. For example from the list, I want to load only the files with the names, 2334.csv, 1243.csv and 13245.csv.
Stephen23
Stephen23 le 22 Nov 2021
Modifié(e) : Stephen23 le 22 Nov 2021
"I want to select them based on a feature of the file name."
And how will you select them? Or, more importantly, how do you plan on telling MATLAB which ones you have selected?
Are you going to tell MATLAB which files you want by writing down the names of three files? Or specifying some property of the filename/etc that can be uniquely matched to exactly 3 files? Or are you going to pick 3 random files? Or read the filenames from another file? Or get the user to specify them? Or something else... ?
"For example from the list, I want to load only the files with the names, 2334.csv, 1243.csv and 13245.csv."
By "list" do you mean the list of filenames returned by DIR ? Or your own "list" of files that you want to process?

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 22 Nov 2021
csvFiles = dir('*.csv') ; % you are in the folder where csv files are present
N = length(csvFiles) ;
for i = 1:N
thisFile = csvFiles(i).name
% do what you want
end

Catégories

En savoir plus sur Large Files and Big Data dans Centre d'aide et File Exchange

Modifié(e) :

le 22 Nov 2021

Community Treasure Hunt

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

Start Hunting!

Translated by