フィルターのクリア

how should I copy the selected files to another folder whose name contains 'mytext'

3 ビュー (過去 30 日間)
ANKUR KUMAR
ANKUR KUMAR 2017 年 10 月 7 日
コメント済み: Cedric 2017 年 10 月 8 日
I have length(F) files are there in a folder. This program gives the 'fname' which contains all the selected files whose name contains '201306'. I want to move/copy these selected files to another folder. How should I do this from the script. Doing manually just by reading the names is such a difficult task and not satisfactory for myself.
F = dir('*.nc');
c = 0 ;
for j = 1:length(F)
fname = F(j).name ;
if ~isempty(strfind(fname,'201306'))
c = c+1 ;
i{c} = fname ;
end
end

採用された回答

Cedric
Cedric 2017 年 10 月 7 日
編集済み: Cedric 2017 年 10 月 7 日
Use
copyfile( fname, dest ) ; % or movefile( fname, dest ) ;
where dest can be defined as
dest = fullfile( 'DestinationFolder', fname ) ; % or just a folder name
in your IF statement instead of the two lines that you have now.
MOST IMPORTANT: test using a copy of your files first! If you make a mistake when building the destination of MOVEFILE, you can easily loose files (by overwrite).
PS1: note that both functions accept wildcards, so you can certainly avoid the loop and leave it to the wildcard/pattern/function to copy/move all relevant files in one shot.
PS2: the destination can be a folder name, there is no need for a file name. Yet, if you want to rename files (e.g. prefix/suffix), you can do it by defining a destination file name.
  6 件のコメント
ANKUR KUMAR
ANKUR KUMAR 2017 年 10 月 8 日
Its done sir. Thank you.
Cedric
Cedric 2017 年 10 月 8 日
Awesome! I'll keep an eye on the thread in case there is anything.

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

その他の回答 (0 件)

カテゴリ

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