打开一个文件名,该文件名具有更改的特定文件模式

b4qexyjb  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(341)

我使用下面的代码从文件中读取内容,因为我需要将.mnu文件的内容复制到另一个.fld文件中。

with open(MS577007.mnu') as myfile:
        contents = myfile.read()
print(contents)

.mnu文件每个月都会更改,因此我正在编写一个脚本来自动执行此操作。如何使用regex打开.mnu文件中的内容?*。mnu不起作用。

eanckbw9

eanckbw91#

您需要获取所有以mnu结尾(扩展名为)的文件名。

from glob import glob

# Find all files

files = glob("*.mnu")

# Loop in files as file

for file in files:
    # Open each file and print content
    with open(file, "r") as myfile:
        contents = myfile.read()
        print(contents)

相关问题