File operations‎ > ‎

File commands



create directory, if not exit
dirname = 'NewDirectory'
if ~isdir(dirname), mkdir(dirname); end 
  

get filename (sample) list of a directory
dir('*.csv')

read all '.csv' files and extract samplenames

fileFormat = '.csv'
dirSamples = '/path/to/data/'
 sdir = dir([dirSamples,'*',fileFormat]) 
% struct info of directory
 numSamples = numel(sdir);
 SampleFilename = cell(numSamples,1);
 SampleIDs = cell(numSamples,1);
  for i=1:numSamples
   SampleFilename{i} = sdir(i).name;
   SampleIDs{i} = strrep(SampleFilename{i},fileFormat, ''); % remove ending '.csv'
  end

SampleFilename
SampleIDs
 




Comments