필터 지우기
필터 지우기

Rename File in a Different Folder

조회 수: 5 (최근 30일)
MATLAB_Soldier
MATLAB_Soldier 2022년 11월 4일
댓글: Rik 2022년 11월 4일
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
MATLAB_Soldier
MATLAB_Soldier 2022년 11월 4일
It is text.
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