forked from mayankgb2/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto-files.py
More file actions
81 lines (71 loc) · 2.38 KB
/
auto-files.py
File metadata and controls
81 lines (71 loc) · 2.38 KB
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
75
76
77
78
79
80
81
#!/usr/bin/env python3
import os, time, shutil
"""
dont have fb, sorry
subcribed by code house
"""
def get_file_name():
mypath1=input("Enter the file: ")
mypath = r"{}".format(mypath1)
onlyfiles = [f for f in os.listdir(mypath) if os.path.isfile(os.path.join(mypath, f))]
return (onlyfiles, mypath)
def into_folder_year(get_file_name,mypath):
"""
Given file name with Created date details list
Make new folder or exist folder using Created date in file details
"""
count = 0
for i in get_file_name:
# needed path in photo_file
photo_file = f"{mypath}\{i}"
#get the Created date in file
time1 = os.path.getmtime(photo_file)
#get the Year(Created date) in file
year_file = time.strftime("%Y",time.localtime(time1))
# get the path in year
create_folder_year = f"{mypath}\{year_file}"
# check the dir exist or not
if not os.path.isdir(create_folder_year):
os.mkdir(create_folder_year)
# make copy into folder
shutil.copy2(photo_file,f"{create_folder_year}\{i}")
count += 1
print(i, " Count: ", count)
def into_folder_month(get_file_name,mypath):
"""
Given file name with Created date details list
Make new folder or exist folder using Created date in file details
"""
count = 0
for i in get_file_name:
# needed path in photo_file
photo_file = f"{mypath}\{i}"
#get the Created date in file
time1 = os.path.getmtime(photo_file)
#get the Yeamontheated date) in file
month_file = time.strftime("%m",time.localtime(time1))
# get the path in month
create_folder_month = f"{mypath}\{month_file}"
# check the dir exist or not
if not os.path.isdir(create_folder_month):
os.mkdir(create_folder_month)
# make copy into folder
shutil.copy2(photo_file,f"{create_folder_month}\{i}")
count += 1
print(i, " Count: ", count)
def main():
get_file_name1 , mypath = get_file_name()
print("""
Please choose which date:
1) Month
2) Year
""")
ch = int(input("Choose the number : "))
if ch == 1:
into_folder_month(get_file_name1,mypath)
elif ch ==2:
into_folder_year(get_file_name1,mypath)
else:
print("Error Choose Wrong Number")
if __name__ == "__main__":
main()