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?
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!