-
Notifications
You must be signed in to change notification settings - Fork 2
/
Os.py
101 lines (88 loc) · 3.2 KB
/
Os.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
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
import os,shutil,glob,win32api
#todo: #Lock-----#Share# -Send To Desktop-Properties-- -
def cd(path):
os.chdir(path)
def back():
os.chdir('..')
def newfolder(Name):
try:
cd.mkdir(Name)
except FileExistsError:
#bind it to a dialog box containing the message below
print('This Folder Already Exists')
def showcurdir():
print(os.getcwd())
class Folder:
def __init__(self,Path):
self.Path=Path
self.password=''
def showdir(self):
for x in os.listdir(self.Path):
print(x)
def compress(self,ArchieveName, Format, DestPath):
if Format == 'bztar' or Format == 'gztar' or Format == 'tar' or Format == 'xztar' or Format == 'zip':
if '/' in ArchieveName or ':' in ArchieveName or '*' in ArchieveName or '?' in ArchieveName or '"' in ArchieveName or '<' in ArchieveName or '>' in ArchieveName or '|' in ArchieveName:
print('Invalid FileName')
else:
shutil.make_archive(DestPath+'\\'+ArchieveName, Format, self.Path)
else:
print('Invalid Format')
#def lock
def delete(self):
for i in os.listdir(self.Path):
try:
os.remove(self.Path+'\\'+i)
except PermissionError:
os.removedirs(self.Path+'\\'+i)
os.removedirs(self.Path)
#os.rmdir(
#except FileNotFoundError:
# print('Theres No Folder Like That :)')
def searchextension(self,extension):
os.chdir(self.Path)
for file in glob.glob("*."+extension):
print(file)
def searchfile(self,keyword):
#its not case sensitive
counter=0
if type(keyword)==str:
for i in os.listdir(self.Path):
if keyword.lower() in i.lower():
print(i)
counter=1
if counter==0:
print('There was no file named %s in this directory'%(keyword))
else:print('Invalid Input')
def hidden(self):
win32api.SetFileAttributes(self.Path, 0x02)
def readonly(self):
win32api.SetFileAttributes(self.Path, 0x01)
def normal(self):
win32api.SetFileAttributes(self.Path, 0x80)
class File:
def __init__(self,Path):
self.Path=Path
self.password=''
self.format=self.Path[self.Path.index('.')+1:len(self.Path)]
self.dir=self.Path[:self.Path.index('.')-2]
def copy(self,TargetPath):
shutil.copy2(self.Path,TargetPath)
def rename(self,NewName):
os.rename(self.Path,self.dir+'\\'+NewName)
def cut(self,TargetPath):
shutil.copy2(self.Path,TargetPath)
os.remove(self.Path)
def delete(self):
try:
os.remove(self.Path)
except FileNotFoundError:
print('Theres No File Like That :)')
def hidden(self):
win32api.SetFileAttributes(self.Path, 0x02)
def readonly(self):
win32api.SetFileAttributes(self.Path, 0x01)
def normal(self):
win32api.SetFileAttributes(self.Path, 0x80)
file='C:\\Users\\Mahdi-PC\\Downloads\\Soroush Downloads\\Images\\1.png'
Dir='C:\\Users\\Mahdi-PC\\Downloads\\Soroush Downloads\\Images\\1'
#win32api.GetLogicalDriveStrings()