概述
只能遍历一层的code:
path = 'E:car20160918MAdataimage';
pth = 'E:car20160918MAdataimgtmp';
fileExt = '*.jpg';
files = dir(fullfile(path,fileExt));
len = size(files);
for i=1:len
fileName = strcat(path,files(i,1).name)
copyfile(fileName, pth);
end;
能遍历多层code:
% <span style="font-family: Arial, Helvetica, sans-serif;">RangTraversal script</span>
function [ mFiles ] = RangTraversal( strPath )
%定义两数组,分别保存文件和路径
mFiles = cell(0,0);
mPath = cell(0,0);
mPath{1}=strPath;
[r,c] = size(mPath);
while c ~= 0
strPath = mPath{1};
Files = dir(fullfile( strPath,'*.*'));
LengthFiles = length(Files);
if LengthFiles == 0
break;
end
mPath(1)=[];
iCount = 1;
while LengthFiles>0
if Files(iCount).isdir==1
if Files(iCount).name ~='.'
filePath = [strPath Files(iCount).name '/'];
[r,c] = size(mPath);
mPath{c+1}= filePath;
end
else
filePath = [strPath Files(iCount).name];
[row,col] = size(mFiles);
mFiles{col+1}=filePath;
end
LengthFiles = LengthFiles-1;
iCount = iCount+1;
end
[r,c] = size(mPath);
end
mFiles = mFiles';
end
%% The directory of your files
str = 'E:/car/20160918MA/data/label/';
pth = 'E:car20160918MAdatamark';
%% The use of depth-first walk
%mFiles = [];
%[mFiles, iFilesCount] = DeepTravel(str,mFiles,0)
%mFiles = mFiles';
%% The use of breadth first walk
mFiles2 = RangTraversal(str)
len = size(mFiles2);
for i=1:len
fileName =mFiles2{i};
copyfile(fileName, pth);
end;
参考:http://blog.csdn.net/carson2005/article/details/17263083
http://blog.csdn.net/guoxiaojie_415/article/details/21317323
http://blog.csdn.net/stpeace/article/details/8230476
最后
以上就是糊涂水杯为你收集整理的matlab遍历文件并完成文件移动的全部内容,希望文章能够帮你解决matlab遍历文件并完成文件移动所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复