use of movefile to move files to another dir

조회 수: 6 (최근 30일)
YOGESH
YOGESH 2011년 8월 28일
Hello, e.g. I have some files named
ab01.sun, cd023.sun, sdf45.sun, wad23.sun
I want to move a file into a subfolder after its work is done. I made a string of filenames and a code like this.
ls_al = dir;
justfiles = ls_al(~[ls_al.isdir]); %only for files
savepath = Y:\ykumkar\MyWork\;
for k = 1:length(justfiles)
filename = justfiles(k).name;
[MyOut, X] = MyFunctionyk(filename);
sp=[savepath char(filename) '.mat'];
save(sp, 'MyOut', 'X');
Now I want to move the first file to a subfolder 'done_files' after the function is run and the output is saved and so on.
movefile ('justfiles(k)', './done_files/'); % need help here
disp 'Done for the file justfiles(k)'; % need help here
end

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 8월 28일
What is your question? A few things.
  1. savepath='Y:\ykumkar\MyWork\';% need to have single quotes for sting assignment
  2. sp=[savepath,filename,'.mat'); %no need to use char() since filename is already a string
  3. movefile(filename,fullfile('./done_files/',filename));

YOGESH
YOGESH 2011년 8월 28일
Thanks Fangjun, rest of the code works well, only it is not moving files to the subdirectory after its work is done. I tried as you said,
movefile(filename,fullfile('./done_files/',filename));
but got error.
Undefined function or method 'eq' for input arguments of type 'struct'.
Error in ==> fullfile at 39
elseif (f(end)==fs) || (part(1)==fs || (bIsPC && (f(end)=='/' || part(1)=='/')) )
filename is a struct.
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2011년 8월 29일
The error seems to come from fullfile(). Take a look at help fullfile to see how it should be used. It basically put path and file name together. You can also use [PathStr,filesep,FileName] too, where filesep is defined by MATLAB. type 'filesep' to see it.
YOGESH
YOGESH 2011년 8월 29일
thanks Fangjun,
i managed it.
actually filename is a 'struct', this means i had to do
movefile(filename.name,'./done_files/');

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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by