How to Rename and Delete empty files using Mat-LAB?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 24 de Feb. de 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 comentarios
Azzi Abdelmalek
el 24 de Feb. de 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)
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!