python - Copy duplicate file and change name -


so i'm looking make backup of file every 2 times, maximum of 30 backups @ once. once there 30 backups, function deletes backups , starts on again (again, creating 30 backups, once every 2 seconds).

because i'm creating 30 copies of same file, need change name python dosen't overwrite file (main0.db, main1.db, main2.db, main3.db...etc). in order this, i've created variable gets appended filename (i) , increased 1 each time function runs.

the problem because have to(?) decalre variable inside function, every time runs variable gets reset, , file created main0.db.

any ideas?

hey, i'm looking make backup of file every 2 times, maximum of 30 backups @ once. once there 30 backups, function deletes backups , starts on again (again, creating 30 backups, once every 2 seconds).

because i'm creating 30 copies of same file, need change name python dosen't overwrite file (main0.db, main1.db, main2.db, main3.db...etc). in order this, i've created variable gets appended filename (i) , increased 1 each time function runs.

the problem because have to(?) decalre variable inside function, every time runs variable gets reset, , file created main0.db.

any ideas?

import os  import glob  import threading  import shutil  def check():   = 0   threading.timer(2, check).start()   listpath = 'c:\users\billy\desktop\new folder'  num_files = len([f f in os.listdir(listpath)              if os.path.isfile(os.path.join(listpath, f))])  #counts files in directory     if num_files < 30:         copypath = 'c:\users\billy\desktop\new folder\main%d.db' %          + 1            shutil.copy2('c:\main.db', copypath)  else:         files = glob.glob('c:\users\billy\desktop\new folder\*')         f in files:             os.remove(f)         = 0  #if theres less 30 files, creates copy of file, iterates filename 1   #else deletes files in folder, resets file name iterator 0.   return  check() 

thanks


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -