Rename File in a Different Folder

3 次查看(过去 30 天)
Hey all,
I am trying to use the movefile command to rename a file using variables and current date.
If I use this code and the REPORT.txt is located in the working folder, it works absolutely fine:
movefile('REPORT.txt', fullfile(prjNo + 'REPORT'+ date +'.txt'));
However, the file I am trying to rename is located in a subfolder of the working folder. I have tried the following options but none of them works:
% Option 1:
movefile('OUT\REPORT.txt', fullfile(prjNo + 'REPORT'+ date +'.txt'));
% Option 2:
movefile(fullfile(workingfolder, + 'OUT\REPORT.txt'), fullfile(prjNo + 'REPORT'+ date +'.txt'));
Can someone point out where the problem is or offer an elegant alternative solution please?
Many thanks.
  7 个评论
Rik
Rik 2022-11-4
I personally would prefer sprintf instead of strcat, but this is equivalent to what I would suggest.
Note that explicitly including the working directory is not required.

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2022-11-4
编辑:Stephen23 2022-11-4
new = fullfile(prjNo + 'REPORT'+ date +'.txt'); % odd use of FULLFILE.
movefile(fullfile('.','OUT','REPORT.txt'),fullfile('.','OUT',new))
Note that '.' refers to the current directory.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by