Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Traversing thru folder
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Pg

Posts: 132
Registered: 1/24/09
Traversing thru folder
Posted: Aug 27, 2013 9:58 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi,

I have 9 different folder describing different regions. Inside each folder i have some 100's of text file which i need to read and do further processing. But i need my program automatically do all these operation. I wrote following code for that:

list = dir('my path name');
isub = [list(:).isdir];
Region = {list(isub).name}'; % extracting region name
Region(ismember(Region,{'.','..'})) = [];

for idx = 1:length(Region)
waitbar(idx/length(Region))

Station_name = dir(sprintf(Region{idx,1})); % displaying list of .text file in folder
StationIndex = find(~[Station_name.isdir]);
Region_name = sprintf(Region{idx,1});

for i = 1:length(StationIndex)
Station = Station_name(StationIndex(i)).name
fprintf('Region name = %s, Station name = %s\n',Region{idx,1}, Station); % displaying each station name
end
end


But the problem is as my region name is variable (which is 9 in this case, the 9 different folder) I am unable to load the data from each different folder, which is stored in text format. After fprintf command I need to read this text files from individual folders. I tried with load, which didn't work for me. The error i'm getting:

Unable to read file '107188.txt': no such file or directory.

because this file is in one of the folder, whose index is idx = 1 in this case, Pls. help how i can address this issue. Thanks,



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.