Manage directories and save a new file in a specific directory

3 次查看(过去 30 天)
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!

回答(2 个)

G PRAKASH
G PRAKASH 2014-1-24
编辑:Walter Roberson 2014-1-24
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 2014-1-24
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.

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by