1- from file_system import (
2- create_folder , create_file , list_contents , read_file , delete_file ,
3- delete_folder , change_directory , go_back , print_working_directory
4- )
1+ from file_system import *
52
63def display_help ():
7- """Displays available commands."""
84 commands = """
95Available commands:
106- mkdir <folder_name> : Create a folder
@@ -13,8 +9,9 @@ def display_help():
139- read <file_name> : Read a file
1410- rm <file_name> : Delete a file
1511- rmdir <folder_name> : Delete a folder
12+ - mv <old_name> <new_name> : Rename a file or folder
1613- cd <folder_name> : Change directory
17- - back : Move to the parent directory
14+ - cd .. : Move to the parent directory
1815- pwd : Print the current working directory
1916- help : Show this help menu
2017- exit : Exit the program
@@ -23,48 +20,60 @@ def display_help():
2320
2421
2522def main ():
26- """Command interpreter for the file system."""
27- print ("Welcome to the Python Terminal Virtual File System!" )
28- display_help ()
29-
3023 while True :
31- command = input ("\n >>> " ).strip ()
24+ command = input ("Admin@Python-Terminal ~ % " ).strip ()
3225 if not command :
3326 continue
3427
35- parts = command .split (" " , 1 )
28+ parts = command .split (" " , 2 )
3629 cmd = parts [0 ].lower ()
37- arg = parts [1 ] if len (parts ) > 1 else None
30+ arg1 = parts [1 ] if len (parts ) > 1 else None
31+ arg2 = parts [2 ] if len (parts ) > 2 else None
3832
39- if cmd == "mkdir" and arg :
40- print (create_folder (arg ))
41- elif cmd == "touch" and arg :
42- print (create_file (arg ))
33+ if cmd == "mkdir" and arg1 :
34+ print (create_folder (arg1 ))
35+ elif cmd == "touch" and arg1 :
36+ print (create_file (arg1 ))
4337 elif cmd == "ls" :
4438 contents = list_contents ()
4539 if isinstance (contents , list ):
4640 print ("\n " .join (contents ) if contents else "Directory is empty." )
4741 else :
4842 print (contents )
49- elif cmd == "read" and arg :
50- print (read_file (arg ))
51- elif cmd == "rm" and arg :
52- print (delete_file (arg ))
53- elif cmd == "rmdir" and arg :
54- print (delete_folder (arg ))
55- elif cmd == "cd" and arg :
56- print (change_directory (arg ))
43+ elif cmd == "read" and arg1 :
44+ print (read_file (arg1 ))
45+ elif cmd == "rm" and arg1 :
46+ print (delete_file (arg1 ))
47+ elif cmd == "rmdir" and arg1 :
48+ print (delete_folder (arg1 ))
49+ elif cmd == "mv" and arg1 and arg2 :
50+ print (rename_item (arg1 , arg2 ))
51+ elif cmd == "cd" and arg1 :
52+ print (change_directory (arg1 ))
53+ elif cmd == "cd" :
54+ print ("zsh: cd must have 1 argument" )
5755 elif cmd == "back" :
5856 print (go_back ())
5957 elif cmd == "pwd" :
6058 print (print_working_directory ())
6159 elif cmd == "help" :
6260 display_help ()
6361 elif cmd == "exit" :
64- print ("Exiting the program. Goodbye! " )
62+ print ("[process Completed] " )
6563 break
64+ elif cmd == "alias" and arg1 and arg2 :
65+ alias (arg1 , arg2 )
66+ elif cmd :
67+ if arg1 :
68+ arg2 = ""
69+ search_alias (cmd , arg1 , arg2 )
70+ else :
71+ arg1 = ""
72+ arg2 = ""
73+ search_alias (cmd , arg1 , arg2 )
6674 else :
67- print ("Unknown command. Type 'help' for a list of commands." )
75+ if arg1 and arg2 :
76+ search_alias (arg1 , arg2 )
6877
6978if __name__ == "__main__" :
7079 main ()
0 commit comments