問題: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