필터 지우기
필터 지우기

How do I move files from current directory to a subfolder?

조회 수: 4 (최근 30일)
Aoife
Aoife 2014년 1월 16일
댓글: Aoife 2014년 1월 17일
I'm a new matlab user so apologies. I want to move files from my current directory to a subfolder.
The filenames are structured as follows
Y1_ANN1.ext, Y1_ANN2.ext....,Y10_ANN10.ext
I have set the current directory to that in which the files are currently located.
The destination folder is sub-folder two levels below the current directory.
This is what I have done so far but for some reason it doesn't seem to be working (I will be looping through values of j and k but just want it to work for the first file first). I keep on getting an error message that the file doesn't exist. I have checked the cd and it is correct and I have checked that 'namefile' is in the cd but it still isn't working. Any ideas? Thanks.
clear all
allsubj = { 'Y1'};
blocks = {[1:4] };
anndatafolder=sprintf('%s/%s',parentFolder, annulusFolder);
for j=1
for k=1
part=strcat('Y',num2str(j));
block=strcat('_ANN',num2str(k));
namefile = sprintf('%s%s%s',part,block,'.bdf');
newloc=sprintf('%s/%s/%s', anndatafolder,part,'XXX')
cd=anndatafolder
movefile(namefile,newloc);
end
end

답변 (1개)

Walter Roberson
Walter Roberson 2014년 1월 17일
cd=anndatafolder sets a variable named "cd" to the contents of "anndatafolder".
cd(anndatafolder)
would change directories using the content of "anndatafolder" as the name of the directory.
Note that the cd() only needs to be done once before the "for j" loop.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by