Hello,
I'm using App designer and I'm tryng to change the name of a file with the name writtend on a text edit field.
For example if i have 'oldname.txt' i want to be able to change it in a name i write in an edit field
How can i do it?

 採用された回答

Ajay Kumar
Ajay Kumar 2019 年 11 月 20 日
編集済み: Ajay Kumar 2019 年 11 月 20 日

0 投票

You can do this. Suppose you entered 'oldname' in text editfield. i.e.
your_editfield.Value = 'oldname';
now save the file using the name
yourfile = % your character array
size_file = size(yourfile);
doc_name = [your_editfield.Value, '.txt'];
fid = fopen(fullfile(yourpath,doc_name),'w');
for i= 1:size_file(1)
fprintf(fid, '%s\n',yourfile(i,:));
end
fclose(fid);

5 件のコメント

Siria Fumagalli
Siria Fumagalli 2019 年 11 月 20 日
i don't have character array but a file
yourfile = 'filecompl.txt';
size_file = size(yourfile);
doc_name = [app.NomeFileEditField.Value, '.txt'];
fid = fopen(fullfile(doc_name),'w');
for i= 1:size_file(1)
fprintf(fid, '%s\n',yourfile(i,:));
end
fclose(fid);
In this way i have a file containig the phrase 'filecompl.txt'
What i want is that filecompl.txt change in doc_name
Ajay Kumar
Ajay Kumar 2019 年 11 月 20 日
I am confused here. Do you have a text file ready? and you want to read it and rename it using matlab editfields?
Siria Fumagalli
Siria Fumagalli 2019 年 11 月 20 日
Exactly, except I don't want to read it, I only want to change the name using the edit field
Ajay Kumar
Ajay Kumar 2019 年 11 月 20 日
yourfile = 'filecompl.txt';
doc_name = [app.NomeFileEditField.Value, '.txt'];
movefile(yourfile,doc_name)
Siria Fumagalli
Siria Fumagalli 2019 年 11 月 20 日
This works perfectly, thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgrammatic Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by