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

96 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Image Analyst
Image Analyst il 23 Dic 2021
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 Commento
Jeffrey Beckstead
Jeffrey Beckstead il 23 Dic 2021
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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by