试题要求:

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

 

答案:

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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2021-10-05
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案