简体   繁体   中英

How do I open a directory (folder) then open a file in the directory - discord.py

How do I open a directory (Folder) then open a file in the directory?

you can open the file directly with open(path)
For Example(1):

file = open('file.txt','r')
print(file.read())
file.close()

Or if you wish to see all files in a current directory you can see with the help of OS module.
For Example(2):

import os
dir_list = os.listdir()#for getting all files n folder in the current path

it will show all the files n folders name in list format.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM