MATLAB: How to locate some specific files

data location

Hello Everyone,
Can someone please help me,
I have 100 excel files, and each file is located on diffrent folder in the drive.
For eg.
file 1 = C:\DATA_DIR\TEST_1\2018_11_26.0001\Excel.xlsx
file 2 = C:\DATA_DIR\TEST_1\2018_11_26.0002\Excel.xlsx
file 3 = C:\DATA_DIR\TEST_1\2018_11_26.0003\Excel.xlsx
.
.
.
file 100 = C:\DATA_DIR\TEST_1\2018_11_26.0100\Excel.xlsx
In each excel file, the data is located at cell (1,1).
What I want to do, take the data from every excel file and save it in one single Excel file and the data should be saved in one single column.
The code I have, was good enough for small amout of data, but In this case and in future, I'll have bigger amount of data, and I'm looking for something, where I don't have to specify the each folder location to save my data in one single excel file.
I really appreciate you help.
Thank you.

Best Answer

Hi,
you can use the compose function to create a string array with the file names in different folders like your example:
folder_pattern = 'C:\DATA_DIR\TEST_1\2018_11_26.0001\Excel.xlsx';
A= 1:100;
newText = compose("%04d",A);
folder_new = string(zeros(100,1));
for k = 1:numel(A)
folder_new(k) = replaceBetween(folder_pattern,'C:\DATA_DIR\TEST_1\2018_11_26.','\Excel.xlsx',newText(k))
end
As result you get a string array like this:
folder_new =
100×1 string array
"C:\DATA_DIR\TEST_1\2018_11_26.0001\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0002\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0003\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0004\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0005\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0006\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0007\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0008\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0009\Excel.xlsx"
.
.
.
"C:\DATA_DIR\TEST_1\2018_11_26.0096\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0097\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0098\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0099\Excel.xlsx"
"C:\DATA_DIR\TEST_1\2018_11_26.0100\Excel.xlsx"
If you include your operations on the single files into the for loop, you can process all operations in one step.
Best rregards
Stephan