简体   繁体   English

在python中,如何在目录中输出具有相同扩展名的所有文件名?

[英]In python,how to output all the files name with the same extension in a directory?

I want to output the files name by using ~/*.java command. 我想使用〜/ *。java命令输出文件名。 I can check if it is a java file but I really don't know how to output and read all the files by *.java command. 我可以检查它是否是java文件,但我真的不知道如何通过* .java命令输出和读取所有文件。

Use the glob module: 使用glob模块:

import glob
glob.glob('*.java')

暂无
暂无

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

相关问题 在目录python中搜索所有具有相同名称的文件 - Search all files with same name in a directory python 将所有以相同名称开头的文件复制到 python 的不同目录中 - Copy all the files which begin with the same name to a different directory in python 如何使用Python递归复制目录中具有特定扩展名的所有文件? - How to recursively copy all files with a certain extension in a directory using Python? 将目录中的所有文件复制到新目录中,同时在 Python 中重命名同名文件 - Copy all files within directory into new directory while renaming files with same name in Python 在 Python 中查找扩展名为 .txt 的目录中的所有文件 - Find all files in a directory with extension .txt in Python 如何将子文件夹中所有特定文件类型的文件重命名为具有相同文件扩展名但文件名相同的名称 - How to rename all specific filetypes of files within subfolders to name with same file extension but same file name 如何更改目录和文件夹的所有文件的扩展名 - how to change extension of all the files of a directory and folder 有没有办法创建一个函数来加载目录中的所有数据文件,然后输出他们的文件名和内容?-Python 3 - Is there a way to create a function to load all data files in directory and then output their file name and content?-Python 3 如何打印没有扩展名的目录中的文件? PYTHON - How to print files in a directory without extension? PYTHON 从 Python 中具有相同文件扩展名的多个文件的目录中读取文件 - Read File From Directory with Multiple Files of the Same File Extension in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM