“diretório de arquivos de contagem de python” Respostas de código

diretório de arquivos de contagem de python

import os
len(os.listdir(directory))
Yawning Yacare

diretório de arquivos de contagem de python

# accepts any number of paths, 
# returns the total amound of files (not dirs) that are in the given paths
# looks recursively

def countFiles(*paths):
    """
    :param paths: list of all paths, the number of files are added
    :return: return the number of files (not directories) in the folders recursively (subfolders are checked as well)
    """
    def helper(path: str):
        count = 0
        # iterate through all files and dir names in path
        for fileName in os.listdir(path):
            filePath = join(path, fileName)
            if isfile(filePath): # if file, increment
                count += 1
            elif isdir(filePath): # if dir, recursively count files in dir
                count += helper(filePath)
        return count

    numFiles = 0
    for path in paths:
        numFiles += helper(path)
    return numFiles
Yucky Yak

Respostas semelhantes a “diretório de arquivos de contagem de python”

Perguntas semelhantes a “diretório de arquivos de contagem de python”

Mais respostas relacionadas para “diretório de arquivos de contagem de python” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código