-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileOps.py
86 lines (75 loc) · 2.08 KB
/
FileOps.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
# author: bzym2
# describe: Example plugin.
import os
import shutil
def onLoad():
print("[FileOps] Loaded successfully.")
def preHook():
print("[FileOps] Pre-hook triggered.")
def afterHook():
print("[FileOps] After-hook triggered.")
def registerCommands():
return {
'ls': ls_command,
'cp': cp_command,
'mv': mv_command,
'rm': rm_command,
'touch': touch_command
}
def ls_command(args):
"""Lists the contents of a directory."""
if len(args) > 1:
path = args[1]
else:
path = os.getcwd()
try:
files = os.listdir(path)
print("\n".join(files))
except FileNotFoundError:
print(f"Error: Directory {path} not found.")
def cp_command(args):
"""Copies a file."""
if len(args) == 3:
src, dst = args[1], args[2]
try:
shutil.copy(src, dst)
print(f"Copied {src} to {dst}.")
except FileNotFoundError:
print(f"Error: {src} not found.")
else:
print("Usage: cp <source> <destination>")
def mv_command(args):
"""Moves a file."""
if len(args) == 3:
src, dst = args[1], args[2]
try:
shutil.move(src, dst)
print(f"Moved {src} to {dst}.")
except FileNotFoundError:
print(f"Error: {src} not found.")
else:
print("Usage: mv <source> <destination>")
def rm_command(args):
"""Removes a file."""
if len(args) == 2:
file = args[1]
try:
os.remove(file)
print(f"Removed {file}.")
except FileNotFoundError:
print(f"Error: {file} not found.")
else:
print("Usage: rm <file>")
def touch_command(args):
"""Creates an empty file or updates the timestamp."""
if len(args) == 2:
file = args[1]
with open(file, 'a'):
os.utime(file, None) # Update the timestamp
print(f"Touched {file}.")
else:
print("Usage: touch <file>")
def getStyles():
return {
'fileops_theme': 'fileops> $ ' # Custom theme for file operations
}