Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python count files directory

import os
len(os.listdir(directory))
Comment

How to count the number of files in a directory using Python

import os, os.path

# simple version for working with CWD
print len([name for name in os.listdir('.') if os.path.isfile(name)])

# path joining version for other paths
DIR = '/tmp'
print len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
Comment

PREVIOUS NEXT
Code Example
Python :: append a zeros column numpy 
Python :: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 43350 
Python :: sang nguyen to python 
Python :: discord.py run 
Python :: how to get an input into a list python 
Python :: figsize param in pandas plot 
Python :: sys.path[0] 
Python :: django admin customization 
Python :: anova test in python 
Python :: python iterate backwards through list 
Python :: conda env 
Python :: factorial in python 
Python :: django __str__ self multiple 
Python :: adf test python 
Python :: loop through list of tuples python 
Python :: multipart/form data multipart encoder python 
Python :: python print raw string 
Python :: numpy initialize 2d array 
Python :: get sum from x to y in python 
Python :: sort rows in csv file using python pandas 
Python :: add two datetime python 
Python :: python find in largest 3 numbers in an array 
Python :: how to create a tuple from csv python 
Python :: python tkinter change color of main window 
Python :: change python3 as default for mac 
Python :: how to get a number from a string in python 
Python :: excel get unique values from column formula 
Python :: python function to scale selected features in a dataframe pandas 
Python :: how to find 1 st digit in python 
Python :: python pop element 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =