How to use DIR to extract file data (name, date, location/a​ddress/tra​nsit) from multiple folders and subfolders?

조회 수: 9 (최근 30일)
Hi everyone,
I've read other posts regarding dir but they didn't seem to help me. I'm trying to use dir to get a structure containing file names, dates, and locations and then export it into an excel file. The issue I have been having is that I can't seem to automate this and have to manually move my .m file to each folder of interest and run it in order to gather this information. I'm not sure how to move down each folder and then return to repeat the process automatically. This is what I have right now, but I'm fairly new to this.
x=dir;
writetable(struct2table(x), 'test.xlsx')
So my question is: How can I search through multiple folders and their subfolders for documents and gather this info and put it into a structure that can be exported as an excel sheet?
Here is an example of the folder of interest (crossed out names for security purposes). Each of these files has multiple subfolders, each containing documents and more subfolders. Thanks!

채택된 답변

Fangjun Jiang
Fangjun Jiang 2018년 9월 18일
x=dir(fullfile(MyFolder,'**/*.*')) will give you all the files and folders in MyFolder and all its subfolders.
  댓글 수: 5
rbme17
rbme17 2018년 9월 19일
Thank you so much, this is exactly what I was looking for! I would like to add that the file name needs to be quoted with apostrophes:
x=dir(fullfile('MyFolder','**/*.*'))
dpb
dpb 2018년 9월 19일
" the file name needs to be quoted with apostrophes"
Only if is character literal; if MyFolder is a variable it can not be quoted.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by