How to copy files but not folders from one folder to destination?

15 ビュー (過去 30 日間)
Zhangxi Feng
Zhangxi Feng 2019 年 7 月 1 日
回答済み: Zhangxi Feng 2019 年 7 月 1 日
Not sure why I am having difficulty searching for this but all the questions I found were just about copying specific file or specific patterns of files.
Is there a quick way to ask copyfile to copy only the files but not the folders that may also be in the directory to a destination directory?
Thanks!
Jesse
  2 件のコメント
dpb
dpb 2019 年 7 月 1 日
Not by itself, no...it's not that smart.
Couple ways to work around limitations; probably simplest in Matlab alone is to use dir('*.*') and iterate over the contents checking each entry is not a directory before passing to copyfile.
Another job really best to pass to the underlying OS with appropriate switches to whatever command is appropriate for the OS you're using.
Zhangxi Feng
Zhangxi Feng 2019 年 7 月 1 日
Yeah so I implemented this with the dir command and removing all the items that are directories then iterate through each of the remaining files with copyfile.
Thanks!

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

採用された回答

Zhangxi Feng
Zhangxi Feng 2019 年 7 月 1 日
For others who may have a similar question, I achieved this goal by using the following:
sourceDir = dir(runSource);
sourceDir([sourceDir.isdir]) = [];
for k = 1:numel(sourceDir)
sourceFile = [sourceDir(k).folder,'/',sourceDir(k).name];
destFile = [curDir,'/',sourceDir(k).name];
copyfile(sourceFile,destFile);
end

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by