forked from OpenPIV/openpiv-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadTXTDir.m
59 lines (54 loc) · 1.36 KB
/
ReadTXTDir.m
1
function [filenames] = ReadTXTDir(dirname,data)% READTXTDIR - Lists all the .txt files in the directory and returns the% list of files for a certain pattern: '.txt' or '_noflt.txt' or '_flt.txt'%%% Syntax:[filenames] = ReadTXTDir(dirname,data)%% Inputs:%% dirname - Directory name, default = '.'% data - 'txt' or '_noflt.txt' or '_flt.txt'%% Outputs:%% filenames - list of files%% Example:%% txtfilenames = ReadTXTDir('./results','_noflt.txt');%%% AUTHOR : Alex Liberzon % Copyright (c)2012 Tel Aviv University%%if nargin < 2 data = 'txt';endswitch data case{'_noflt.txt'} % a) direc = dir([dirname,filesep,'*_noflt.txt']); case{'_flt.txt'} %b) direc = dir([dirname,filesep,'*_flt.txt']); case{'txt'} % c) direc = dir([dirname,filesep,'*.txt']); tmp = struct('name',[]); k = 0; for i=1:length(direc) if length(findstr(direc(i).name,'_')) < 2 k = k + 1; tmp(k).name = direc(i).name; end end direc = tmp;endif ~isempty(str2num(direc(1).name(1:length(direc(1).name)-4))) for i = 1:length(direc) n(i) = str2num(direc(i).name(1:length(direc(i).name)-4)); end [junk,j] = sort(n); direc = direc(j);endfilenames={};[filenames{1:length(direc),1}] = deal(direc.name);% filenames = sortrows(filenames);