【发布时间】:2018-04-21 01:35:18
【问题描述】:
我有一个包含许多子目录的目录,其中包含文件。我想在“App_integrations”文件夹中打开以“root.vrpj”或“root.vprj”结尾的文件,并将包含“table”一词的行复制到另一个文件中。
到目前为止,我已经设法使用此代码访问每个文件:
for root, dirs, files in os.walk(movedir):
for filename in files:
if filename.endswith(("root.vrpj", "root.vprj")):
问题是我现在拥有的只是我想访问的文件的名称,我被困在这里。
【问题讨论】:
-
您可以使用
with open("filename","r") as readFile打开文件,然后使用for line in readFile遍历文件中的行,这可能会让您进一步开始docs.python.org/2/tutorial/inputoutput.html,快乐编码:)
标签: python python-2.7 copy file-copying