python試題寫一個函數接收參數,返回該文件夾中的文件路徑以及包含文件夾中文件的路徑

 

試題要求:函數

寫一個函數接收參數,返回該文件夾中的文件路徑以及包含文件夾中文件的路徑spa

 

答案:code

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
相關文章
相關標籤/搜索