python how to count ever yfile in fodler

Solutions on MaxInterview for python how to count ever yfile in fodler by the best coders in the world

showing results for - "python how to count ever yfile in fodler"
Elsie
22 May 2020
1import os
2directory = 'mydirpath'
3
4number_of_files = len([item for item in os.listdir(directory) if os.path.isfile(os.path.join(directory, item))])
5
Clary
26 Aug 2019
1import os
2print len(os.listdir(os.getcwd()))
3
Adame
18 Jun 2016
1import fnmatch
2
3print len(fnmatch.filter(os.listdir(dirpath), '*.txt'))
4
Tremaine
07 Jul 2020
1import os
2isfile = os.path.isfile
3join = os.path.join
4
5directory = 'mydirpath'
6number_of_files = sum(1 for item in os.listdir(directory) if isfile(join(directory, item)))
7
Greta
22 Feb 2020
1def count_files(dir):
2    return len([1 for x in list(os.scandir(dir)) if x.is_file()])
3
Lucia
15 Sep 2016
1import os
2
3list = os.listdir(dir) # dir is your directory path
4number_files = len(list)
5print number_files
6
Leon
26 Aug 2018
1import os
2
3file_count = sum(len(files) for _, _, files in os.walk(r'C:\Dropbox'))
4print(file_count)
5
Silvia
25 Feb 2016
1def directory(path,extension):
2  list_dir = []
3  list_dir = os.listdir(path)
4  count = 0
5  for file in list_dir:
6    if file.endswith(extension): # eg: '.txt'
7      count += 1
8  return count
9
Vincent
24 Jan 2018
1import os
2
3onlyfiles = next(os.walk(dir))[2] #dir is your directory path as string
4print len(onlyfiles)
5
similar questions
queries leading to this page
python how to count ever yfile in fodler