我正在尝试从配置文件中定义的路径中读取文件。然后我需要删除超过14天的某些文件。我没有编写用于检查时间的代码,但是在这里查找文件失败了。
代码
def cleanup():
global config, logger, status, file_path
config = ConfigParser.RawConfigParser()
config.read('config.cfg')
for section in sorted(config.sections(), key=str.lower):
if not config.has_option(section, 'server.user_name'):
continue
env.user = config.get(section, 'server.user_name')
env.password = config.get(section, 'server.password')
host = config.get(section, 'server.ip')
file_path= config.get(section, 'server.path')
print "Trying to connect to {} server.....".format(section)
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True, host_string=host):
try:
print "Connected to {} server".format(section)
for filename in os.listdir(file_path):
print filename
except Exception as e:
print e
print 'Could not connect to {} server\n'.format(section)
if __name__ == "__main__":
cleanup()
配置
[sync location]
server.ip = 110.109.117.113
server.user_name = root
server.password = 123
server.path = /usr/rosh/test
这是我得到的错误。
错误
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/roradhak/Work/Scripts/YES-tidy/rosh_files_tidy.py
Trying to connect to sync location server.....
Connected to sync location server
[Errno 2] No such file or directory: '/usr/rosh/test'
Could not connect to sync location server
有人可以帮助我获取配置中设置的文件夹下的文件吗?