Count files of multiple paths


I want to count files in multiple paths

For example:
“C:\Users\unichank\Documents\Test1\Folder1” has 10 files
“C:\Users\unichank\Documents\Test1\Folder2” has 5 files
“C:\Users\unichank\Documents\Test1\Folder3” has 2 files
“C:\Users\unichank\Documents\Test1\Folder4” has 1 file

I want the result to be:
C:\Users\unichank\Documents\Test1\Folder1: 10
C:\Users\unichank\Documents\Test1\Folder2 : 5
C:\Users\unichank\Documents\Test1\Folder3 : 2
C:\Users\unichank\Documents\Test1\Folder4 : 1


What part of the task are you having trouble with?

  • getting the files in a folder?
  • counting the number of files?
  • printing?
  • all of it?

It is safer to use forward-slashes for paths, even in Windows.
Backslashes are used for string escapes, so you can get unexpected

You can get the files in a folder like this:

import os
contents = os.listdir("C:/Users/unichank/Documents/Test1/Folder1")

Does that help? Can you do the rest on your own?

Hello @steven.daprano

What if I have different paths? Like:

like @steven.daprano said earlier, it’s better when we know the exact place you’re stuck.
Perhaps you can share the code you’ve written so far and we can start from there.