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.
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.
import os
def get_files_and_folders(directory):
return os.listdir(directory)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.