フィルターのクリア

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

8 ビュー (過去 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.
  1 件のコメント
Aoife
Aoife 2014 年 1 月 17 日
thank you. worked perfectly

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by