-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fileop.py
executable file
·61 lines (32 loc) · 1.22 KB
/
Fileop.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
from subprocess import call as shell
def File(**kwargs):
"""This Fucntion is Shortcut for File operations
Example : File(Path = test.txt , Mode = 'wb' , Content = 'test', stat = [True , "+h +r +s"]) """
Data = kwargs
with open(Data['Path'] , Data['Mode']) as file :
if file.mode == 'r' or file.mode == "rb" == file.mode == "r+":
return file.read()
if file.mode == 'w' or file.mode == "a" or file.mode == "wb":
file.write(Data['Content'])
if file.mode == "rl":
return file.readlines()
# shell('attrib {} {}'.format(Data['stat'][1] ,Data['Path']))
def header(Path , header):
"""This Fucntion write headers for file like csv...ext
Example : header(test.txt , 'Data, Date')
"""
try:
with open(Path , 'r') as file :
try:
f_line = next(file)
if header != f_line :
open(Path , "a").write(header)
except StopIteration :
open(Path , "a").write(header)
except IOError as e :
with open(Path , 'wb') as file:
file.write(header)
def more(**kwargs):
Data = kwargs
shell('more {}'.format(Data['Path']), shell = 1)
shell('del {}'.format(Data['Path']), shell = 1)