Get a directory listing of only directories / folders when folders have 1000's of files

96 次查看(过去 30 天)
Is there a way to do the DOS command "dir /A:D" and get only a listing of directories / folders below a parent? My subfolders have 10,000's of files within them. The methods given in other posts get a listing of all folders and files using "dir", and strip out the file using "isdir" field. The "ls" function on Unix can use the "ls -d" to get only the directories. Is there an equivalent on Windows?

采纳的回答

Image Analyst
Image Analyst 2021-12-23
You could do it in MATLAB like this:
topLevelFolder = pwd; % Wherever you want.
fileList = dir(topLevelFolder);
areFolders = [fileList.isdir];
folderList = fileList(areFolders);
numFolders = length(folderList);
% Define the min number of files to record.
minFilesInFolder = 1000;
% Find out how many files are in each one
finalFolderNameList = {};
for k = 1 : length(folderList)
thisFolder = fullfile(folderList(k).folder, folderList(k).name);
filePattern = fullfile(thisFolder, '*.*');
files = dir(filePattern);
numFiles = length(files);
fprintf('"%s" has %d files in it.\n', thisFolder, numFiles);
% If it has the min number of files in it, save this folder name in our final list.
if numFiles >= minFilesInFolder
% Store this folder in the final list.
finalFolderNameList = [finalFolderNameList; thisFolder];
end
end
  1 个评论
Jeffrey Beckstead
Jeffrey Beckstead 2021-12-23
Great. After submitting question, I thought more on what I might want. Your method allows me to add in the additional needs that would have come after getting the initial listing. You are a much faster typer/coder than I to develope that sample code in that time. Thank you

请先登录,再进行评论。

更多回答(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