“Python Cara Menghitung Pernah Yfile di Fodler” Kode Jawaban

Python Cara Menghitung Pernah Yfile di Fodler

import os
isfile = os.path.isfile
join = os.path.join

directory = 'mydirpath'
number_of_files = sum(1 for item in os.listdir(directory) if isfile(join(directory, item)))
Courageous Cobra

Python Cara Menghitung Pernah Yfile di Fodler

import os

onlyfiles = next(os.walk(dir))[2] #dir is your directory path as string
print len(onlyfiles)
Courageous Cobra

Python Cara Menghitung Pernah Yfile di Fodler

import os

file_count = sum(len(files) for _, _, files in os.walk(r'C:\Dropbox'))
print(file_count)
Courageous Cobra

Python Cara Menghitung Pernah Yfile di Fodler

def count_files(dir):
    return len([1 for x in list(os.scandir(dir)) if x.is_file()])
Courageous Cobra

Python Cara Menghitung Pernah Yfile di Fodler

import os
directory = 'mydirpath'

number_of_files = len([item for item in os.listdir(directory) if os.path.isfile(os.path.join(directory, item))])
Courageous Cobra

Python Cara Menghitung Pernah Yfile di Fodler

import os

list = os.listdir(dir) # dir is your directory path
number_files = len(list)
print number_files
Courageous Cobra

Python Cara Menghitung Pernah Yfile di Fodler

import fnmatch

print len(fnmatch.filter(os.listdir(dirpath), '*.txt'))
Courageous Cobra

Python Cara Menghitung Pernah Yfile di Fodler

import os
print len(os.listdir(os.getcwd()))
Courageous Cobra

Python Cara Menghitung Pernah Yfile di Fodler

def directory(path,extension):
  list_dir = []
  list_dir = os.listdir(path)
  count = 0
  for file in list_dir:
    if file.endswith(extension): # eg: '.txt'
      count += 1
  return count
Courageous Cobra

Jawaban yang mirip dengan “Python Cara Menghitung Pernah Yfile di Fodler”

Pertanyaan yang mirip dengan “Python Cara Menghitung Pernah Yfile di Fodler”

Lebih banyak jawaban terkait untuk “Python Cara Menghitung Pernah Yfile di Fodler” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya