Manage directories and save a new file in a specific directory
조회 수: 1 (최근 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!
댓글 수: 0
답변 (2개)
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')
댓글 수: 0
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!