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

2 ビュー (過去 30 日間)
bioter
bioter 2013 年 2 月 24 日
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 Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by