Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return number of files in directory and subdirectory

Trying to create a function that returns the # of files found a directory and its subdirectories. Just need help getting started

like image 893
Bob Avatar asked Jun 04 '13 05:06

Bob


People also ask

How do I count the number of files in a directory and subdirectories?

To count all the files and directories in the current directory and subdirectories, type dir *. * /s at the prompt.

Is there a way to count the number of files in a folder?

Alternatively, select the folder and press the Alt + Enter keys on your keyboard. When the Properties window opens, Windows 10 automatically starts counting the files and folders inside the selected directory. You can see the number of files and folders displayed in the Contains field.

How do I find the number of subdirectories in a directory?

Using the ls Command. The ls command lists the directories and files contained in a directory. The ls command with the -lR options displays the list (in long format) of the sub-directories in the current directory recursively.


1 Answers

One - liner

import os cpt = sum([len(files) for r, d, files in os.walk("G:\CS\PYTHONPROJECTS")]) 
like image 180
kiriloff Avatar answered Sep 19 '22 07:09

kiriloff