-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.py
80 lines (67 loc) · 2.38 KB
/
file.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
import shutil as __shutil
import os as __os
from time import strftime, localtime
import hashlib as __hashlib
def rm(file):
isFile = __os.path.isfile(file)
isDir = __os.path.isdir(file)
if not isFile and not isDir:
print("File or Directory not found!")
quit()
if isFile:
__os.remove(file)
if not __os.path.exists(file):
print("File successfully deleted!")
elif isDir:
__shutil.rmtree(file)
if not __os.path.exists(file):
print("Directory successfully deleted!")
def rd(file):
if not __os.path.exists(file):
print("File not found!")
quit()
else:
if __os.path.isdir(file):
print("Can't read folder")
quit()
with open(file) as f:
print(f.read())
def w(file, content=""):
if __os.path.isdir(file):
print("Can't write folder")
else:
with open(file, "w") as f:
f.write(content)
with open(file) as f:
check_if_written = f.read()
if check_if_written == content:
print("Successfully written on file")
else:
print("Failed!")
def c(name, fileOrDir=""):
if fileOrDir == "file" or fileOrDir == "":
with open(name, "w") as f:
f.close()
elif fileOrDir == "dir":
__os.mkdir(name)
def inf(file):
if not __os.path.exists:
print("File or folder not found!")
else:
print("*****Informations*****")
if __os.path.isfile(file):
print("Size of file: " + str(__os.path.getsize(file)) + " bytes")
else:
ordnergroesse_bytes = sum(__os.path.getsize(__os.path.join(file, datei))
for datei in __os.listdir(file)
if __os.path.isfile(__os.path.join(file, datei)))
print("Size of folder: " + str(ordnergroesse_bytes) + " bytes")
print("Last modified time: " + str(strftime('%Y-%m-%d %H:%M:%S', localtime(__os.path.getmtime(file)))))
print("Creation time: " + str(strftime('%Y-%m-%d %H:%M:%S', localtime(__os.path.getctime(file)))))
def md5(file):
with open(file,"rb") as f:
bytes = f.read() # read file as bytes
readable_hash = __hashlib.md5(bytes).hexdigest()
print(readable_hash)
if __name__ == "__main__":
print("Please import the module from another file to use it!")