필터 지우기
필터 지우기

How to move file from one folder to another folder?

조회 수: 106 (최근 30일)
Kamran Afroz
Kamran Afroz 2023년 12월 28일
댓글: Stephen23 2023년 12월 28일
Hi,
I am renaming my existing file uisng
movefile(oldfilename,rename)
Then I want to move this "rename" file to other folder but how to use "movefile" function where I have stored filename in "rename"?
Thanks.
  댓글 수: 1
Stephen23
Stephen23 2023년 12월 28일
The accepted answer calls MOVEFILE twice, which is not required. You can do this with one call:
oldName = 'oldName.txt';
newName = 'newName.txt';
oldPath = 'absolute or relative path to where the file is saved';
newPath = 'absolute or relative path to where you want the file';
movefile(...
fullfile(oldPath,oldName),...
fullfile(newPath,newName))

댓글을 달려면 로그인하십시오.

채택된 답변

Debraj Maji
Debraj Maji 2023년 12월 28일
I understand that you are trying to rename a file using "movefile" function and then you want to move it to a different location. Given below is the required template that will allow you to do the necessary.
oldfilename = 'your file path';
rename = 'The new name for the file';
% Rename the existing file
movefile(oldfilename, rename);
newFolderPath = 'Define the path to the new folder where you want to move the file';
% Create the full path for the new location by concatenating the folder path and the new filename
newFilePath = fullfile(newFolderPath, rename);
% Move the renamed file to the new folder
movefile(rename, newFilePath);
For more information on the "movefile" function you can refer to the following documentation:
I hope this resolves your query,
With regards,
Debraj.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by