Trying to create a function that returns the # of files found a directory and its subdirectories. Just need help getting started
To count all the files and directories in the current directory and subdirectories, type dir *. * /s at the prompt.
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.
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.
One - liner
import os cpt = sum([len(files) for r, d, files in os.walk("G:\CS\PYTHONPROJECTS")])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With