Renaming and deleting files using MatLab

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

Jan
Jan 2013년 2월 22일
How do you determine which new name matches to which rawdataXYZ?

댓글을 달려면 로그인하십시오.

답변 (2개)

Babak
Babak 2013년 2월 21일

0 개 추천

doc system
system
Execute operating system command and return result
Syntax
system('command')
[status, result] = system('command')
[status,result] = system('command','-echo')

댓글 수: 3

Jan
Jan 2013년 2월 21일
I do not see a connection between this answer and the question.
bioter
bioter 2013년 2월 24일
Me neither, :/
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.

댓글을 달려면 로그인하십시오.

the cyclist
the cyclist 2013년 2월 22일

0 개 추천

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

I have two folders "1.Batch" and "2.Batch", both containing, more than 60 files, named "rawdata001.txt","rawdata002.txt","rawda… and so on.. Initially, I renamed everything manually to "pO2.txt", "Oxygen.txt", "Carbondioxide.txt" etc.,
I then retrieved the names from the manually name-changed files containing folder, using dir command, i need to know how can i create a loop so that the names can be changed from rawdata to the specific name,
i have a matrix named
names = ['pO2','oxygen'.......] oldnames = ['rawdata001.txt',....60.txt]
i need to rename it from rawdata to pO2,
Then some of these files are empty, they just have headers and units in them but no values, that is, first two lines have names on it, but nothing after that, no values or numbers,
i also would like to know how to remove them using a loop, i tried many things, delete command, but its getting trickier,
Thanks for the reply
This cannot work:
names = ['pO2','oxygen']
The horizontal concatenation of two strings is one string:
names = 'pO2oxygen'
Please post the code you have tried. "It's getting trickier" does not allow to give a suggestion for an improvement.
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".

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2013년 2월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by