file renaming using python

ぐ巨炮叔叔 提交于 2019-12-12 06:04:55

问题


I am trying to rename a file in which it is auto-generated by some local modules but I was wondering if using os.listdir is the only way for me to filter/ narrow down this file. This file will always be generated before it is removed and the code will generate the next one (still in the same directory) based on the next item in list.

Basically, whenever this file is generated, it comes in the following file path: /user_data/.tmp/tempLibFiles/2015_03_16_192212_182096.con

I had only wanted to rename the 2015_03_16_192212_182096 into connectionFile while keeping the rest the same.


回答1:


You can also use the glob module to narrow down the list of files to the one that matches a particular pattern. For example:

import glob
files = glob.glob('/user_data/.tmp/tempLibFiles/*.con')


来源:https://stackoverflow.com/questions/29075818/file-renaming-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!