A object oriented implementation of a file system using the Directory
and File
classes. The file system supports basic operations such as creating directories, navigating through the file system, listing directories, creating and copying files, and more.
This program uses python str, dictionaries and lists to implement the Directory class and file class
The Directory
class represents a directory in the file system. It has
name
for the name of directories and uses str,
subdirs
for the list of subdirectories and uses Dictionaries,
files
for the list of files and uses Dictionaries
The FileSystem
class serves as an interface for the file system and provides methods to interact with it. It includes methods such as mkdir
, cd
, ls
, cp
, mv
, rm
, touch
, cat
, and echo
.
The File
class represents a text file with a name and content. It has a clone
method to create a deep copy of the file.
-
Ensure you have Python installed on your system.
-
Run the
main.py
file to start the file system interface. -
Use commands like
mkdir
,cd
,ls
,cp
,mv
,rm
,touch
,cat
, andecho
to interact with the file system. -
Optionally, use the
save_state
andload_state
commands to save and load the file system state.
#FOR running only on BASH
# if you don't want to load prev state and save curr state
python main.py '{"save_state": true, "load_state":false, "path": "data.json"}'
# if you want to load prev state an d save curr state
python main.py '{"save_state": true, "load_state":true, "path": "data.json"}'
# if you want to load prev state
python main.py '{"save_state": true, "load_state":true, "path": "data.json"}'
# if you don't want to save prev state and don't want to load prev state
python main.py
#FOR running only on cmd
python main.py "{\"save_state\": true, \"load_state\":true, \"path\": \"data.json\"}"
-
Creating a new directory:
mkdir new_dir
-
Changing directory:
cd new_dir
-
Listing directories:
ls
-
Copying a directory:
cp src_dir target_dir
-
Moving a file:
mv src_file.txt target_dir
-
Removing a directory:
rm dir_to_remove
-
Adding a new text file:
touch new_file.txt
-
Reading the content of a text file:
cat existing_file.txt
-
Writing content to a text file:
echo existing_file.txt Input: "Hello World"
-
Exiting the file system:
exit