フィルターのクリア

Reading From Different Directories in a for loop (fopen from different directories)

1 回表示 (過去 30 日間)
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.

採用された回答

per isakson
per isakson 2012 年 5 月 6 日
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.
  1 件のコメント
Orkun OZENER
Orkun OZENER 2012 年 5 月 8 日
Dear Per Isakson,
Thansk for you answer again. It is really an enhanced and advanced function.
Thanks for your note. I downloaded to my folder. And I am trying to understand the function. Thanks for your answer and for your provious answer about reading the file. I am just working on code. If you dont mind May be in the future I will ask some questions again. best Regards.

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2012 年 5 月 6 日
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.
  1 件のコメント
Orkun OZENER
Orkun OZENER 2012 年 5 月 8 日
Dear Image Analyst,
Thanks for your answer..
It works fine..and so easy.
thansk again

サインインしてコメントする。


Walter Roberson
Walter Roberson 2012 年 5 月 6 日
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
  1 件のコメント
Orkun OZENER
Orkun OZENER 2012 年 5 月 8 日
Dear Mr.Roberson,
Thanks for your answer and for your approach.
You script also solved my problem.
Best regards.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by