问题: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