How to stop overwriting?

5 views (last 30 days)
Haron Shaker
Haron Shaker on 13 Mar 2021
Answered: Jan on 13 Mar 2021
Dear all,
I wrote a function, which lists the directory of a given URL. Now I got several URLs which I want run over a loop to list all directories of the URLs in a array.
My problem is that this function overwrites the founded stuff of an URL (iteration i) with the founded directory of the followed URL of (iteration = i+1) and so on, until it just gives the directory of the last URL of the loop instead of all. How can I change it?
The URLs are attached.
folderCellArray = {}
data = readcell('founded_medicine_folder.xls')
saveFileName = 'try.xls'
for i = 1:4
url = data{i,1}
dd= listAllDirectories(url, folderCellArray, saveFileName)
%I guess some concat step is missing here
end

Accepted Answer

Jan
Jan on 13 Mar 2021
Maybe:
dd = cell(1, 4);
for i = 1:4
url = data{i, 1};
dd{i} = listAllDirectories(url, folderCellArray, saveFileName)
end
But what happens inside listAllDirectories? The name "saveFileName" might mean, that something is overwritten there. Then either instruct this function to append the data. Or use a new file name in each itereation:
for i = 1:4
url = data{i, 1};
saveFileName = sprintf('try%03d.xls', i);
dd = listAllDirectories(url, folderCellArray, saveFileName)
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!