How to Rename and Delete empty files using Mat-LAB?

2 次查看(过去 30 天)
I am a newbie to Mat-Lab, and I will try to explain my question as clearly as possible, bear with me.
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,
Then some of these files are empty, they just have headers and units in them but no values, i also would like to know how to remove them using a loop, i tried many things, but its getting trickier,
Can somebody help me?

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-2-24
To rename files. For example
liste_of_files={'rawdat001','rawdata002',...,'rawdata10'}
You want to rename them with
new_name{'carbon','oxygene',...}
for k=1:10
copyfile([yourpath '/' liste_of_file{k}],[yourpath '/' new_name{k}])
end
to delete the empty file by code, I don't think that's a good idea, unless you are experimented.
  2 个评论
bioter
bioter 2013-2-24
But is there an option by which i can specify that if the thrid row and column are empty the script can delete files?
Azzi Abdelmalek
Azzi Abdelmalek 2013-2-24
fid = fopen('file.txt');
line1 = fgetl(fid);
res=line1;
while ischar(line1)
line1 = fgetl(fid);
res =char(res,line1)
end
fclose(fid);
n=size(res,1)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by