Reading From Different Directories in a for loop (fopen from different directories)
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
My problem is,
I can not read the file from different directory/folder My file name is same all the time . It is " kEG1____1.gid ".(It is atext file)
C:\......Case_Set_1.135\simulation.dir\kEG1____1.gid
C:\......Case_Set_1.136\simulation.dir\kEG1____1.gid
C:\......Case_Set_1.137\simulation.dir\kEG1____1.gid
...
I can read and process the text file individually with the code that Mr/Ms Per Isakson wrote from this forum.It uses fopen(..9) for opening the file.The link is here. http://www.mathworks.com/matlabcentral/answers/37437-textscan-reading-after-a-specified-term-or-a-row-and-writing-matrix )
But the problem is all the files located in different directories.
C:\......Case_Set_1.135\simulation.dir\kEG1____1.gid
C:\......Case_Set_1.136\simulation.dir\kEG1____1.gid
C:\......Case_Set_1.137\simulation.dir\kEG1____1.gid
...
I tried to obtain directory names with sprintf but it gives an error.
for i=136:137
fullFileName=sprintf('C:\Users\KARTAL\Dropbox\CaseDenemeler\BWF25PRE_2000\boost\135-143set.Case_Set_1.1%d\simulation.dir\kEG1____1.gid',i)
end
But it gives " Invalid escape sequence appears in format string. See help sprintf for valid escape sequences." which I think it is an backslash forwardslash error..
But I could not solve the problem.
anyone can help me about this situation.
Best Regards.
0 commentaires
Réponse acceptée
per isakson
le 6 Mai 2012
There is a function in the FEX, Recursive directory listing - Enhanced RDIR, which I guess will help you out.
The call will be something like
sad = rdir( 'root_something\**\kEG1*1.gid' )
maybe
sad = rdir( 'c:\Users\KARTAL\Dropbox\CaseDenemeler\BWF25PRE_2000\boost\135-143set.Case_Set_1.13*\**\kEG1*1.gid' )
There are two rdir in the FEX. I intended to link to Recursive directory listing. That is the one that has become part of my Matlab. However, I guess either one will do the job.
Plus de réponses (2)
Image Analyst
le 6 Mai 2012
Simple solution: use forward slashes instead of backslashes. Even Windows handles them just fine:
fullFileName=sprintf('C:/Users/KARTAL/Dropbox/CaseDenemeler/BWF25PRE_2000/boost/135-143set.Case_Set_1.1%d/simulation.dir/kEG1____1.gid',i)
Another tip: Use genpath() to get a list of all subfolders. Perhaps this may come in useful in the event that you don't know all the subfolder names in advance.
Walter Roberson
le 6 Mai 2012
fullFileName=sprintf('%s%d%s', 'C:\Users\KARTAL\Dropbox\CaseDenemeler\BWF25PRE_2000\boost\135-143set.Case_Set_1.1', i, '\simulation.dir\kEG1____1.gid')
end
Voir également
Catégories
En savoir plus sur Search Path dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!