简体   繁体   English

如何打开目录(文件夹)然后打开目录中的文件 - discord.py

[英]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)您可以直接使用open(path)打开文件
For Example(1):例如(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.或者,如果您希望查看当前目录中的所有文件,您可以在OS模块的帮助下查看。
For Example(2):例如(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.它将以列表格式显示所有文件 n 文件夹名称。

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

相关问题 “没有这样的文件或目录”discord.py - FileNotFound 不工作 - "No such file or directory" discord.py - FileNotFound is not working 如何打开特定目录中的文件? - How do I open a file in a specific directory? 如何在 discord.py 中打开事件循环? - How to open an event loop in discord.py? Discord.py 和网络浏览器 | 如何使 web 浏览器仅对消息的作者打开? - Discord.py and Webbrowser | How do I make the web browser open for only the author of the message? Discord.py 没有这样的文件或目录,即使它确实存在 - Discord.py No such file or directory even though it does exist Discord.py Cogs 错误 FileNotFoundError:[Errno 2] 没有这样的文件或目录:'./cogs' - Discord.py Cogs Error FileNotFoundError: [Errno 2] No such file or directory: './cogs' tkinter如何在任何系统上使用特定文件夹(也包含.py脚本)的文件目录打开? - How can tkinter open with file directory of specific folder (also containing .py script) on any system? 无法在 discord.py 的命令中打开和写入文件两次 - Can't open and write a file twice in a command in discord.py PyQt - 如何打开目录文件夹? - PyQt - How to open a directory folder? 如何从 Python 的父目录打开文本文件? - How do I open a text file from a parent directory in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM