python试题写一个函数接收参数,返回该文件夹中的文件路径以及包含文件夹中文件的路径

试题要求:

写一个函数接收参数,返回该文件夹中的文件路径以及包含文件夹中文件的路径

答案:

def print_directory_contents(sPath):
    """
        这个函数接受文件夹的名称作为输入参数,
        返回该文件夹中文件的路径,
        以及其包含文件夹中文件的路径。

        """
    for sChild in os.listdir(sPath):
        sChildPath = os.path.join(sPath,sChild)
        if os.path.isdir(sChildPath):
            print_directory_contents(sChildPath)
        else:
            print sChildPath

猜你喜欢

转载自www.cnblogs.com/rayong/p/9198761.html