How to use DIR to extract file data (name, date, location/address/transit) from multiple folders and subfolders?
10 次查看(过去 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!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196133/image.png)
采纳的回答
Fangjun Jiang
2018-9-18
x=dir(fullfile(MyFolder,'**/*.*')) will give you all the files and folders in MyFolder and all its subfolders.
5 个评论
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 Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!