统计目录下的文件并逐个循环
我在一个目录中有一些不同格式的文件,但我只想读取 .txt 文件并根据计数打印,
示例:(one.txt,two.txt, Three.txt,four.txt,one.xlsx ,two.xlsx)
这里我想统计.txt文件的数量并一一读取所有.txt文件,这里计数是4
读取文件one.txt
print("hello")
读取文件two.txt
print("hello" )
读取文件三.txt
print("hello")
读取文件 four.txt
print("hello")
I have some different format files in a one directory, but i want to read only .txt file and print the based on the count ,
Example: (one.txt,two.txt,three.txt,four.txt,one.xlsx,two.xlsx)
here i want to count the .txt files and read all .txt file one by one , here the count is 4
read file one.txt
print("hello")
read file two.txt
print("hello")
read file three.txt
print("hello")
read file four.txt
print("hello")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用标准库中的 pathlib 包:
You can use pathlib package from the standard library: