This python script backup your directory structure that works on Linux and Windows both. It directly uses the shell to do this task and shell commands are considered very fast compared to file operations does otherwise.
import os, os.path import subprocess import time def backUpDir(path): """ Creates backup of the passed old dir and creates a new dir. The backed up dir gets the date and time as the name of the new backed up file. On success, returns a list consising of two values: 0: to signify the success None: means no error occurred. On error, return a list consisting of two values: -1 : to signify the failure error string: the exact error string """ if os.path.exists(path) == True: #dir exists then backup old dir and create new backupDir = path + time.strftime('-%Y-%m-%d-%Hh%Mm%Ss') if os.name == "nt": #NT Sysyem - used the DOS Command 'move' to rename the folder cmd = subprocess.Popen(["mov", path, backupDir], \ shell = True, \ stdout = subprocess.PIPE, \ stdin = subprocess.PIPE, \ stderr = subprocess.PIPE) elif os.name == "posix": #POSIX System - use the appropriate POSIX command to rename the folder. cmd=subprocess.Popen(["mv", path, backupDir], \ shell = True, \ stdout = subprocess.PIPE, \ stdin = subprocess.PIPE, \ stderr = subprocess.PIPE) pass else: # Not supported on other platforms return [-1, "Not supported on %s platform" %(os.name)] (out, err) = cmd.communicate() if len(err) != 0: return [-1, err] else: os.mkdir(path) return [0, None] else: #create new dir os.mkdir(path) return [0, None]
Great job on the blog. Hope to see more such amazing posts. python training in Chennai
Great post!
Thanks for sharing this list!
It helps me a lot finding a relevant blog in my niche!
Java Training in Chennai
Java Training in Coimbatore
Java Training in Bangalore
A big thanks for this sharing this awesome post with us. Read it recently and felt very happy on reading every bit of the blog.
Spoken English Classes in Chennai
Best Spoken English Classes in Chennai
IELTS Coaching in Chennai
IELTS Coaching Centre in Chennai
English Speaking Classes in Mumbai
English Speaking Course in Mumbai
IELTS Classes in Mumbai
IELTS Coaching in Mumbai
IELTS Coaching in Anna Nagar
Spoken English Class in Anna Nagar
Excellent and very cool idea and great content of different kinds of the valuable information's.
Data Analytics Courses in Chennai
Data Analytics Courses
TOEFL Training in Chennai
Spoken English in Chennai
Blockchain Training in Chennai
spanish institute in chennai
content writing training in chennai
Data Analytics Courses in Tambaram
Data Analytics Courses in Adyar
I have read some useful information in your blog.
Python Training in Chennai
Python Training in Training
Python Training in Bangalore
Python Hyderabad
Python Training in Coimbatore
This is a good post and informative and very.thanks for sharing these information with all of us. Discover the ultimate solution for mastering English with Ziyyara Edutech's online home tuition for English. Our expert tutors offer personalized English tuition classes that cater to your unique learning needs.
For more info visit English tuition classes
Thanks for the post. It was worth reading blog.
Linux Course in Pune