-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyTools.py
129 lines (128 loc) · 2.84 KB
/
PyTools.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
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
class tools:
def ginit(self):
import colorama
import os
def __init__(self):
self.ginit()
def __init_subclass__(self):
self.ginit()
class file:
def scan(file,string):
"""
scan a file for a string
"""
file1 = open(file, 'r')
stringl = string.lower()
if stringl in file1.read().lower():
return True
else:
return False
def append(file,string):
"""
append to a file
"""
with open(file,'a') as filea:
filea.write(string)
def overwrite(file,string):
"""
overwrite a file
"""
with open(file,'w') as filew:
filew.write(string)
def read(file):
"""
read a file
"""
with open(file,'r') as filer:
return filer.read()
def create(file):
"""
create a file
"""
open(file,'x')
def check(file):
"""
check if a file exists
"""
try:
if os.path.exists(file):
return True
elif not os.path.exists(file):
return False
except NameError:
import os
if os.path.exists(file):
return True
elif not os.path.exists(file):
return False
def delete(file):
"""
delete a file
"""
try:
os.remove(file)
except NameError:
import os
os.remove(file)
def chdir(path):
"""
change directory
"""
try:
os.chdir(path)
except NameError:
import os
os.chdir(path)
def lsdir(path):
"""
list a directory
"""
try:
return os.listdir(path)
except NameError:
import os
return os.listdir(path)
def ls():
"""
list current directory
"""
try:
return os.listdir(os.getcwd())
except NameError:
import os
return os.listdir(os.getcwd())
class string:
def split(stringtosplit,stringtosplitby):
"""
split a string into an array by a character inside the string
"""
return str(stringtosplit).split(stringtosplitby)
def chop(string):
res = []
for i in str(string):
res.append(i)
return res
def listToString(listc):
string = ''
for i in listc:
string = string + str(i)
return string
def string(inp):
return str(inp)
class console:
def warn(text):
print(colorama.Fore.RED + text + colorama.Fore.RESET)
def comment(text):
print(colorama.Style.DIM + text + colorama.Style.NORMAL)
def print(text):
print(text)
def pcw(text):
print(text)
print(colorama.Style.DIM + text + colorama.Style.NORMAL)
print(colorama.Fore.RED + text + colorama.Fore.RESET)
def newline():
print()
def clear():
os.system('clear')
def wue(text):
input(text)