How to Rename and Delete empty files using Mat-LAB?
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Azzi Abdelmalek
on 24 Feb 2013
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 Comments
Azzi Abdelmalek
on 24 Feb 2013
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)
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!