How to use for loop for files in folders using ls

5 views (last 30 days)
I have 8 different folders and in each, there is a file I want to store from each folder using a for loop. So far, I have:
for i=1:rows %rows of condFiles which are all the folders
%Go to that file
cd(condFiles(i,:));
%Returns csv files as list
VGfiles=ls('*VG_C.CSV');
%Go back to HoboDataLogger
cd ../
It keeps overwriting each file in the folders and only showing the last iteration. How do I store each iteration through loop?

Accepted Answer

Stephen23
Stephen23 on 23 Dec 2014
Don't use cd to change the directory, just create a file path together with your filename:
You can use partial or full paths, and change the directory name in each loop.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!