-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbackup.py
74 lines (56 loc) · 1.73 KB
/
backup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Code to directly use in file to
create directory in home location
Note:- I Have used python package so if you want
to create in the main directory of your project use
pardir+"\\"+name in functions
All the folder operations are done on home
project directory.
"""
from os import chdir
from os import makedirs
from os import removedirs
from os import rename
from os.path import exists
from os.path import pardir
from shutil import copytree
from shutil import move
# Creates a directory
def create_directory(name):
if exists(pardir + "\\" + name):
print("Folder already exists... Cannot Overwrite this")
else:
makedirs(pardir + "\\" + name)
# Deletes a directory
def delete_directory(name):
removedirs(name)
# Rename a directory
def rename_directory(direct, name):
rename(direct, name)
# Sets the working directory
def set_working_directory():
chdir(pardir)
# Backup the folder tree
def backup_files(name_dir, folder):
copytree(pardir, name_dir + ":\\" + folder)
# Move folder to specific location
# Overwrites the file if it already exists
def move_folder(filename, name_dir, folder):
if not exists(name_dir + ":\\" + folder):
makedirs(name_dir + ":\\" + folder)
move(filename, name_dir + ":\\" + folder + "\\")
backup_files("D", "backup_project")
# create_directory("test")
# rename_directory("test", "backup")
# create_directory("test")
# # delete_directory("backup")
# backup_files('D', 'backup_project')
# move_folder(pardir+'\\'+'test.txt', 'D', 'name')
"""
For test purpose:
1. create_directory("test")
2. rename_directory("test","backup")
3. delete_directory("backup")
4. backup_files('D', 'backup_project')
5. move_folder(pardir+'\\'+'test.txt', 'D', 'name')
"""