So löschen Sie Dateien mit einem Python-Skript von einem FTP-server die älter sind als 7 Tage?

Möchte ich schreiben, ein Python-Skript, welches mir erlaubt das löschen von Dateien von einem FTP-Server, nachdem Sie ein gewisses Alter erreicht haben. Ich hab das scipt unter, aber es wirft die Fehlermeldung: WindowsError: [Error 3] The system cannot find the path specified: '/test123/*.*'

Tun jemand eine Idee, wie dieses Problem zu beheben? Vielen Dank im Voraus!

import os, time
from ftplib import FTP

ftp = FTP('127.0.0.1')
print "Automated FTP Maintainance"
print 'Logging in.'
ftp.login('admin', 'admin')

# This is the directory that we want to go to
path = 'test123'
print 'Changing to:' + path
ftp.cwd(path)
files = ftp.retrlines('LIST')
print 'List of Files:' + files 
#--everything works fine until here!...

#--The Logic which shall delete the files after the are 7 days old--
now = time.time()
for f in os.listdir(path):
  if os.stat(f).st_mtime < now - 7 * 86400:
    if os.path.isfile(f):
        os.remove(os.path.join(path, f))
except:
    exit ("Cannot delete files")

print 'Closing FTP connection'
ftp.close()
  • was ist os.directory? Dein code macht nur sehr wenig Sinn. Warum sind Sie versuchen zu löschen Dateien von Ihrem lokalen system?
  • Ich denke, shell/bash-Shell wäre eine bessere alternative zu python
  • ja, aber es muss auf windows laufen. also shell / bash ist nicht eine option in diesem Fall.
InformationsquelleAutor Tom | 2010-05-19
Schreibe einen Kommentar