how read from another dir

7 ビュー (過去 30 日間)
huda nawaf
huda nawaf 2011 年 11 月 6 日
hi, I want to read files in another dir not current dir. when I used dir(name of dir)
not get what I want, but got to current directory .
thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 11 月 6 日
If you pass a quoted directory name to dir(), including any relevant drive letters, then dir() will return information for that directory (or give an error about not being able to get the information.)
However, the 'name' field of the structure that is returned by dir() never includes any part of the name of the directory that was queried: you have to add the directory name in yourself if you want it.
For example,
fileinfo = dir('E:\MyFiles\*.jpg')
then fileinfo.name will never include the E:\MyFiles part, just the E73rk.jpg or whatever the file name is within the directory.
targetdir = 'E:\MyFiles';
targetfiles = '*.jpg';
fileinfo = dir(fullfile(targetdir, targetfiles));
for K = 1 : length(fileinfo)
thisfilename = fullfile(targetdir, fileinfo(K).name);
...
end

カテゴリ

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