-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanupscript.py
More file actions
executable file
·129 lines (111 loc) · 3.87 KB
/
cleanupscript.py
File metadata and controls
executable file
·129 lines (111 loc) · 3.87 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /usr/bin/env python3
import os
import shutil
#Define function for moving files
def move_function(args, dir):
count = 0
for i in args:
shutil.move(args[count], dir)
count = count + 1
print ("This script is designed to cleanup the Home folder")
print ("Starting with the Downloads Folder in /home/$USER")
#Creating homedir variable
homedir = os.environ['HOME']
#Creating downloaddir variable
downloaddir = homedir + "/Downloads/"
#Creating picturedir variable
picturedir = homedir + "/Pictures/"
#Creating documentdir variable
documentdir = homedir + "/Documents/"
#Creating musicdir variable
musicdir = homedir + "/Music/"
#Creating videodir variable
videodir = homedir + "/Videos/"
print ("Moving to the /home/$USER/Downloads folder")
os.chdir(downloaddir)
file_list_docs = []
for root, dirs, files in os.walk(downloaddir):
for f_name in files:
if f_name.endswith('.doc'):
file_list_docs.append(f_name)
if f_name.endswith('.docx'):
file_list_docs.append(f_name)
if f_name.endswith('.pdf'):
file_list_docs.append(f_name)
move_function(file_list_docs, documentdir)
file_list_pics = []
for root, dirs, files in os.walk(downloaddir):
for f_name in files:
if f_name.endswith('.jpg'):
file_list_pics.append(f_name)
if f_name.endswith('.png'):
file_list_pics.append(f_name)
if f_name.endswith('.gif'):
file_list_pics.append(f_name)
move_function(file_list_pics, picturedir)
file_list_video = []
for root, dirs, files in os.walk(downloaddir):
for f_name in files:
if f_name.endswith('.mp4'):o.O
file_list_video.append(f_name)
if f_name.endswith('.flv'):
file_list_video.append(f_name)
if f_name.endswith('.mkv'):
file_list_video.append(f_name)
move_function(file_list_video, videodir)
file_list_music = []
for root, dirs, files in os.walk(downloaddir):
for f_name in files:
if f_name.endswith('.mp3'):
file_list_music.append(f_name)
if f_name.endswith('.m4a'):
file_list_music.append(f_name)
if f_name.endswith('.ogg'):
file_list_music.append(f_name)
if f_name.endswith('.flac'):
file_list_music.append(f_name)
move_function(file_list_music, musicdir)
print("Moving to /home/$USER/ Directory")
os.chdir(homedir)
file_list_docs[]
for root, dirs, files in os.walk(homedir):
for f_name in files:
if f_name.endswith('.docx'):
file_list_docs.append(f_name)
if f_name.endswith('.doc'):
file_list_docs.append(f_name)
if f_name.endswith('.pdf'):
file_list_docs.append(f_name)
move_function(file_list_docs, documentdir)
file_list_pics = []
for root, dirs, files in os.walk(homedir):
for f_name in files:
if f_name.endswith('.jpg'):
file_list_pics.append(f_name)
if f_name.endswith('.png'):
file_list_pics.append(f_name)
if f_name.endswith('.gif'):
file_list_pics.append(f_name)
move_function(file_list_pics, picturedir)
file_list_video = []
for root, dirs, files in os.walk(homedir):
for f_name in files:
if f_name.endswith('.mp4'):
file_list_video.append(f_name)
if f_name.endswith('.mkv'):
file_list_video.append(f_name)
if f_name.endswith('.flv'):
file_list_video.append(f_name)
move_function(file_list_video, videodir)
file_list_music = []
for root, dirs, files in os.walk(homedir):
for f_name in files:
if f_name.endswith('.mp3'):
file_list_music.append(f_name)
if f_name.endswith('.flac'):
file_list_music.append(f_name)
if f_name.endswith('.m4a'):
file_list_music.append(f_name)
if f_name.endswith('.ogg'):
file_list_music.append(f_name)
move_function(file_list_music, musicdir)