matlab遍历文件并完成文件移动
2016-10-25 15:57
232 查看
只能遍历一层的code:
path = 'E:\car\20160918MA\data\image\';
pth = 'E:\car\20160918MA\data\imgtmp\';
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>
%demo
%% The directory of your files
str = 'E:/car/20160918MA/data/label/';
pth = 'E:\car\20160918MA\data\mark\';
%% 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
path = 'E:\car\20160918MA\data\image\';
pth = 'E:\car\20160918MA\data\imgtmp\';
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
%demo
%% The directory of your files
str = 'E:/car/20160918MA/data/label/';
pth = 'E:\car\20160918MA\data\mark\';
%% 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
相关文章推荐
- VC++ MFC文件的移动复制删除更名遍历操作
- VC++ MFC文件的移动复制删除更名遍历操作
- Windows与Linux平台下Matlab遍历文件夹下子文件夹及文件
- 使用matlab遍历文件并同时生成图片
- matlab 移动(复制)文件到另一个文件夹
- matlab 遍历目录下所有文件
- matlab遍历文件
- [matlab] 读取数据-保存数据-文件移动和复制
- MATLAB遍历主文件夹下所有子文件里的特定格式文件
- matlab代码-遍历文件夹中指定类型的文件
- 遍历文件夹并移动其中所有的文件
- matlab 遍历文件夹内文件
- C++, Python, Matlab, Bash 文件目录遍历
- 使用MATLAB遍历指定的子文件夹及其下文件
- VC++ MFC文件的移动复制删除更名遍历操作
- MATLAB 小经验积累(2):MATLAB复制、移动文件和文件夹
- matlab遍历文件夹下的所有文件
- matlab遍历文件夹下指定类型的文件以及子文件夹
- PHP 引入并读取php数据文件,改html后缀为php完成html的一次编写ul,li遍历出现多次li
- VC++ MFC文件的移动复制删除更名遍历操作