简体   繁体   English

如何列出我的存储库中的所有文件夹和文件

[英]How to list all folder and files in my repository

My question how to show the folder in my repository beacause my code now is only showing all files in my repository and i want to see all folders and all files my problem is that i only see file我的问题是如何在我的存储库中显示文件夹,因为我的代码现在只显示我的存储库中的所有文件,我想查看所有文件夹和所有文件我的问题是我只看到文件

I want Video with all his children when i print当我打印时,我想要和他所有孩子的视频

monRepertoire="/home/administrator/Desktop/TP4/"
from os import walk
listeFichiers = []
for (repertoire, sousRepertoires, fichiers) in walk(monRepertoire):
    listeFichiers.extend(fichiers)
    print(listeFichiers)

You may consider glob , it allows recursive search of directories and files, and return a list of them.您可以考虑glob ,它允许递归搜索目录和文件,并返回它们的列表。

import glob
monRepertoire="/home/administrator/Desktop/TP4/"
# use ** and set recursive=True to perform recursive search
listeFichiers = glob.glob(monRepertoire + "**", recursive=True)
print(listeFichiers)

Hope the following function can help you.希望下面的function可以帮助到你。

import os

def get_files_and_folders(directory):
    return os.listdir(directory)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何列出给定变更集的Mercurial存储库中存在的所有文件? - How to list all files present in a mercurial repository at a given changeset? 如何在文件列表中为文件夹中的所有文件添加前缀“_”[Python] - How to prepend the prefix “_” to all files in a folder, in a list of files [Python] 如何列出Google云端硬盘文件夹的所有文件,文件夹,子文件夹和子文件 - How to list all files, folders, subfolders and subfiles of a Google drive folder 如何使用 python 列出 sharepoint 文件夹内的所有文件 - How to list all files inside the folder of sharepoint using python 使用 Python 如何获取 HDFS 文件夹中所有文件的列表? - Using Python how to get list of all files in a HDFS folder? 如何遍历文件夹中的文件并将我的脚本应用于python中的所有文件 - How to iterate through files in a folder and apply my script to all in python 找不到文件/如何让 Python 识别我文件夹中的所有文件? - File not found / How to make Python recognize all the files in my folder? 如何创建包含在同一文件夹中的文件的文件列表? - How to create a file list of my files included in the same folder? 列出位于数据湖中的文件夹中的所有文件 - List All Files in a Folder Sitting in a Data Lake 如何重命名文件夹中的文件列表 - How to rename the list of files in a folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM