MATLAB文件夾路徑生成list

問題:A文件夾有很多圖片,A的路徑是pathA,現在要將A文件下的文件名全部保存到list.txt  。 list.txt路徑在pathout 


code:

        pathout = 'list.txt'
       pathin = 'pathA';            
 
 fp = fopen(pathout,'wt')
 img_all = dir(pathin);
 for i = 1: length(img_all)
     img = img_all(i).name;
     imgpath = strcat(pathin,'/',img);
     fprintf(fp,'%s \n',imgpath);
 end
 fclose(fp) 

這裏會多出來兩個list  爲 pathA/. 和pathA/..


在後續處理中要跳過這兩個:

for ...

   if strcmp(pathin,'.')||strcmp(pathin,'..')
         continue;
     end

end

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章