Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
189 lines (152 loc) · 5.36 KB
/
Copy pathmain.py
File metadata and controls
189 lines (152 loc) · 5.36 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# This is a sample Python script.
# Press Shift+F6 to execute it or replace it with your code.
import os #for file and folder operations
import shutil #for moving, copying and organizing files and folders
import glob #for finding files using patterns
import keyboard
class organizeFiles:
def on_key_y(self):
print("press Y to confirm, N to cancel:")
choice = input().strip().lower()
return choice == 'y'
def fileOrganize(self):
print(" ")
print("First, please let me know what folder path you want to use to organize: ")
path = input("folder path, please insert:")
ifExists = os.path.isdir(path)
if ifExists:
print("path exists") # this is not checked lol.
else:
print('this directory does not exist, try again, also try putting / symbol infront ')
print("Try again. ")
path = input("folder path, please insert:")
ifExists = os.path.isdir(path)
if ifExists:
print("path exists")
else:
print('Sorry, you made a mistake again., Try once again.')
self.fileOrganize()
#print("do you want to loop through the folder and find files by format?")
for files in os.listdir(path):
root, extension = os.path.splitext(files)
print(root + " and " + extension)
print("do you want to create a folder for this extension? choose Yes or No")
#inp = input()
if self.on_key_y():
print("do you want to choose a new folder directory for this new folder? Y/N")
if self.on_key_y():
path = input("insert the new path")
else:
print("the folder will be created in currently selected folder.")
print("choose the name for your new " + extension + " file directory.")
newfolder = input("choose: ")
newpath = path + "/" + newfolder
os.mkdir(newpath)
print(newpath)
for i in os.listdir(path):
roots, extensions = os.path.splitext(i)
if extensions == extension:
filepath = path + '/' + i
shutil.move(filepath, newpath)
else:
print("app is closing")
def moveFile(self): #HAS TO ALSO DETECT THE FILE,
print("insert directory of a file or folder you want to move: ")
path = input(":")
print(" ")
checkIfFile = os.path.isfile(path)
ifExists = os.path.isdir(path)
if checkIfFile or ifExists:
print(" ")
else:
print('Sorry, file/folder doesnt exist, Try once again.')
self.moveFile()
print("choose folder directory you want to move the file/folder to:")
newpath = input(':')
ifExists = os.path.isdir(newpath)
if ifExists:
print("path exists")
shutil.move(path, newpath)
print("file/folder is moved to the new directory folder.")
start()
else:
print("directory doesn't exist. try it all again.'")
print("choose folder directory you want to move the file/folder to:")
newpath = input(':')
ifExists = os.path.isdir(newpath)
if ifExists:
print("path exists")
shutil.move(path, newpath)
print("file/folder is moved to the new directory folder.")
start()
else:
print("directory doesn't exist. try it all again.'")
self.moveFile()
def FindF(self):
path = input("insert a folder of the file where I should find it:")
file = input("insert the name of a file, or a part name, you want to find:")
ifExists = os.path.isdir(path)
if ifExists:
print("path exists")
else:
print("directory doesn't exist. try it all again.'")
self.FindF()
filepath = path + '/' + file
input2 = os.path.isfile(filepath)
if input2:
print(input2)
print("file exists in this folder")
else:
print("file does not exist in this folder.")
print(" ")
repeat = input("you want to find another file? Y/N")
if repeat == "y":
self.FindF()
else:
start()
def Findfile(self):
file = input("insert the name of a file, or atleast part of it, you want to find:")
rootstring = "C://"
start_directory = input("root directory is 'C://' if you know where more or less to look at, insert the directory path, else skip:")
if not start_directory:
start_directory = "C://"
last_directory = ' '
for root, dirs, files in os.walk(start_directory):
rootstring = str(root)
dirstring = str(dirs)
filesstring = str(files)
find = glob.glob(root + '/' + file + '.*')
if find:
print(" ")
print("found it in:")
print(root)
print(" ")
last_directory = root
for i in find:
print(i)
os.startfile(last_directory)
repeat = input("want to find another file? PRESS any button if you want to continue, or ENTER if you want to quit")
if not repeat:
start()
else:
self.Findfile()
# r"C:\Users\jacsi"
def start():
obj = organizeFiles()
print("please choose what you would like to do?")
print("choose if you want:")
print("organize your files according to their format (f.e. .txt) and put them in newly created folders PRESS '1' ?")
print("or just move files/folders from one directory to another PRESS '2'? ")
print("you want to find a certain file by name in a certain folder? PRESS '3'")
print("you want to find a certain file by name anywhere on your C:// disc? PRESS '4'")
print(" ")
input1 = input()
if input1 == '1':
obj.fileOrganize()
if input1 == '2':
obj.moveFile()
if input1 == '3':
obj.FindF()
if input1 == '4':
obj.Findfile()
start()