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