title: How to move from file to file in a loop, MatLab?
body: <p>Is there a way to simply load the name of the first file in a directory without specifying its name, and then in each iteration move on to the next file in the directory?</p>
  
  <p>I have the problem of the file names being named with 1, 1.5, 2,2.5,3, 3.5 endings etc... so num2str(X) in an iteration will not help to locate the file.</p>
  
  <p>I am trying to rename them using strrep(s1,s2,s3), but yet again I run into the same problem of loading them into a loop!</p>
  
  <p>I understand that I should have named them with more planning at first, but these files are much too large to run the simulations again.</p>
  
  <p>This is what I have to rename the files:</p>
  
  <pre><code>%%%RENAMING A FILE%%%
  
  %Search directory to get number of files
   d1=dir('\MATLAB\Data\NumberedQwQoRuns');
   numfiles = length(d1)-2;
  
  
  for a=1:numfiles
  %Search subdirectory if necessary for count of those folders
  d2=dir('\MATLAB\Data\NumberedQwQoRuns\Run'num2str(a));
  subdir = length(d2)-2;
  for b= 1:subdir
  
  origname= PROBLEM???
  
  Newname=['Zdata' num2str(b) '.txt']
  Newfile= strrep(origname, origname, newname)
  movefile(origname,Newfile)
  
  end
  end
  </code></pre>
  
  <p>Thank You Very Much for your help,
  Abid A</p>