Check for subfolders in a folder

25 ビュー (過去 30 日間)
Daniel Boateng
Daniel Boateng 2019 年 3 月 13 日
編集済み: Adam Danz 2019 年 3 月 13 日
I have a folder called Project and in this folder there are various folders. In these various folder there are subfolders in each folder. But i want to check a particular subfolder called Site_Data in one of the folders and copy the content of this Site_Data folder into another folder I have created called Simulation_Data.
copyfolder = '2_Site_Data';
if(exist([cd C:\DesignTool\Projects, copyfolder]))
disp ('folder is found')
WriteDir = C:\DesignTool\Projects\newProject\Simulation_Data'];
copyfile( copyfolder,WriteDir)
end
But its not working. Can anyone help please
  1 件のコメント
Adam Danz
Adam Danz 2019 年 3 月 13 日
編集済み: Adam Danz 2019 年 3 月 13 日
The solution will be similar to the solution from a previous question of yours.
Please take time to understand why solutions work so you can learn from them and apply the new knowledge to future solutions.

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

採用された回答

Adam Danz
Adam Danz 2019 年 3 月 13 日
編集済み: Adam Danz 2019 年 3 月 13 日
Parts that were wrong with your code
  • paths are strings; yours did not have quotes
  • fullfile() will put together paths from nested folder strings
  • The 2nd input to exist() is not required but is recommended to the function knows what to look for.
parent = 'C:\DesignTool\Projects';
WriteDir = 'C:\DesignTool\Projects\newProject\Simulation_Data';
copyfolder = '2_Site_Data';
if exist(fullfile(parent, copyfolder), 'dir')
disp ('folder is found')
copyfile(copyfolder,WriteDir)
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by