Renaming and deleting files using MatLab

5 views (last 30 days)
bioter
bioter on 21 Feb 2013
Hi,
I am trying to rename files in a folder
e.g., rawdata001,rawdata002,rawdata003, etc., upto 100s
with a folder containing the exact same number of files,which i have renamed manually a year ago
e.g., _Batchage, _Oxygen, _CO2, etc.,
I wish to change rawdata001 -> _Batchage,
Also, after renaming, I combine two different sets of files using Matlab, but some of the files are empty, with just headers,
e.g.,
time /tab xyz
h /tab %
is it possible to delete those empty files them using Matlab?
I am noob, hope i explained my question correctly,
Thanks in Advance.
  1 Comment
Jan
Jan on 22 Feb 2013
How do you determine which new name matches to which rawdataXYZ?

Sign in to comment.

Answers (2)

Babak
Babak on 21 Feb 2013
doc system
system
Execute operating system command and return result
Syntax
system('command')
[status, result] = system('command')
[status,result] = system('command','-echo')
  3 Comments
Babak
Babak on 25 Feb 2013
I meant you need to execute a system command, like for example to rename a file from myfile1 to myfile to you can do this,
oldpath = 'C:\myfile1'
oldpath = 'C:\myfile2'
[status, w] = dos(sprintf('ren %s %s',oldpath,newpath));
You could copy, say
dos(sprintf('copy %s %s',oldpath,newpath));
or delete, say
dos(sprintf('del %s %s',oldpath,newpath));
instead.

Sign in to comment.


the cyclist
the cyclist on 22 Feb 2013
It is not clear what you have tried, or where you are stuck. One part of the solution may be the movefile command to "rename" files, and the delete command to delete files.
  3 Comments
the cyclist
the cyclist on 25 Feb 2013
Please do post your code.
But one small step that might help you is that you can store the separate strings in a cell array:
names = {'pO2','oxygen'.......}
Then, when you need each name, you can access it with
names{1}
which is the contents of the first "cell".

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!