Manage directories and save a new file in a specific directory

2 views (last 30 days)
Hello,
I have a bunch of folders named A,B,C... ect. inside a single folder.
Inside each of those folders, I have folders that are dated 7-1-13,7-5-13,7-19-13... ect.
Inside each of those folders, I have anywhere from 2-99 excel files that I need to do processing on.
I don't need to know how to process my data, I just want to have matlab go into each "A,B,C" folder and look at every single sub-folder and be able to write a file inside each "A,B,C" folder.
I have a little code to process all the excel files I just don't know how to navigate through all of these folders. I know 'cd' is the way you change directories but how do I do it so I don't spend 8 hours trying to figure out how to do it! Thanks!

Answers (2)

G PRAKASH
G PRAKASH on 24 Jan 2014
Edited: Walter Roberson on 24 Jan 2014
try this
clc
clear all
close all
M1={'slno','name'};
sheet='test1';
xlswrite('C:\Documents and Settings\Vlsi\Desktop\filename', M1, sheet,'B1:C1')
a=[1:4]';
b={'A';'B';'C';'D'};
xlswrite('C:\Documents and Settings\Vlsi\Desktop\filename', a, sheet,'B2')
xlswrite('C:\Documents and Settings\Vlsi\Desktop\filename', b, sheet,'C2')

Walter Roberson
Walter Roberson on 24 Jan 2014
Just remember that the names returned by dir() do not have the name of the containing directory prefixed to them.
master = 'C:\MyData';
aaa = dir(master);
aaa(~[aaa.isdir]) = []; %get rid of non-dirs
for K = 1 : length(aaa)
thisdir = aaa(K).name;
if strcmp(thisdir, '.') || strcmp(thisdir, '..'); continue; end
thisdir = [master '/' thisdir];
bbb = dir(thisdir);
for J = 1 : length(bbb) ....
...
end
end
Notice there was no "cd" needed.

Categories

Find more on Search Path 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!