我有一个包含一个地理数据库和另外两个文件(txt)的文件夹.我用拉链和拉链.所以现在在这个文件夹中我有gdb,txt,txt和新的zip文件.现在我需要删除那些被压缩的文件,这样只会在文件夹中找到zip文件.我写了以下代码:
def remove_files():
for l in os.listdir(DestPath):
if l.find('zipped.zip') > -1:
pass
else:
print ('Deleting ' + l)
os.remove(l)
Run Code Online (Sandbox Code Playgroud)
但得到了:
Error Info:
[Error 2] The system cannot find the file specified: 'geogeo.gdb'
Run Code Online (Sandbox Code Playgroud)
谁能帮我?先感谢您.
os.listdir仅返回文件名,而不是完整路径.
os.remove如果只给出文件名,则使用当前工作目录.如果当前工作目录不同DestPath,则需要提供完整路径:
os.remove(os.path.join(DestPath,l))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2027 次 |
| 最近记录: |