The principal idea behind my project implementation is to use the underlying custom-designed FileSystem
structure, which conveniently represents the computer file system
data FileSystem =
MkFile String String
| MkDirectory String [FileSystem]
deriving (Eq, Show)
MkFile <name> <content>
- used for creating file instancesMkDirectory <name> <content>
- used for creating directory instances, where content could be comprised of files and directories
For my REPL (Read-Eval-Print Loop), I instantiated additional Command
and Eval
structures, which segregate the code by making it more readable
data MKCommands = MkDir | Touch
deriving (Eq, Show)
data Command = PWDCommand
| CDCommand
| LSCommand
| DIRCommand MKCommands
| CATCommand
| RMCommand
| SHOWCommand
| QUITCommand
deriving (Eq, Show)
data Eval = Continue (Maybe [FileSystem])
| PWD
| LS String
| SHOW String
| QUIT
Due to the provided implementation, I had to define Eval
in order to obtain information whether or not the command is of I/O type or just FileSystem
manipulation
- The provided
Parser.hs
logic plays a pivotal role in the way input is being processed throughout the whole project. Due to the complex logic, the code was partially borrowed from the repository linked down below - The logic, concerned with
FileSystem
manipulation is segregated into distinct code files i.eAdd.hs
,Remove.hs
,Navigation.hs
,Concat.hs
- Clone this repository
git clone https://github.com/Slavi15/File-System.git
# SSH: git clone [email protected]:Slavi15/File-System.git
- Head to
src
directory
cd src
- Load the program
ghci Main.hs
- Run the program
main
By default the program runs with the following file system initially:
fileSystem :: FileSystem
fileSystem = MkDirectory "/" []
pwd
- absolute pathcd <path>
- navigation to the provided subdirectorycd ..
- navigation to the parent directoryls <path | empty>
- prints the contents of the provided directorycat <file_1> <file_2> ... <file_n> > <output_file>
- combines the contents of the provided files into the output filetouch <path | empty> <name_1> <content_1 ++ $> <name_2> <content_2 ++ $> ... <name_n> <content_n ++ $>
- creates files in the provided directorymkdir <path | empty> <dir_1> <dir_2> ... <dir_n>
- creates directories in the provided directoryrm <file_1> <file_2> ... <file_n>
- removes the provided files from the current directoryshow <file>
- prints the content of the provided file in the current directory:q
- termination of the program
Microsoft Windows [Version 10.0.22631.4751]
(c) Microsoft Corporation. All rights reserved.
D:\File-System\src>ghci
GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help
ghci> :load Main.hs
[ 1 of 14] Compiling Core.Command ( Core\Command.hs, interpreted )
[ 2 of 14] Compiling Core.FileSystem ( Core\FileSystem.hs, interpreted )
[ 3 of 14] Compiling Core.Eval ( Core\Eval.hs, interpreted )
[ 4 of 14] Compiling Interact ( Interact.hs, interpreted )
[ 5 of 14] Compiling Output ( Output.hs, interpreted )
[ 6 of 14] Compiling Parser ( Parser.hs, interpreted )
[ 7 of 14] Compiling Utility ( Utility.hs, interpreted )
[ 8 of 14] Compiling Show ( Show.hs, interpreted )
[ 9 of 14] Compiling Remove ( Remove.hs, interpreted )
[10 of 14] Compiling Navigation ( Navigation.hs, interpreted )
[11 of 14] Compiling Add ( Add.hs, interpreted )
[12 of 14] Compiling Concat ( Concat.hs, interpreted )
[13 of 14] Compiling Main ( Main.hs, interpreted )
Ok, 13 modules loaded.
ghci> main
/> ls
/> mkdir dir
/> ls
Directory: dir
/> cd dir
/dir/> ls
/dir/> touch file1 Very cool project! $
/dir/> touch file2 Test concat! $
/dir/> ls
File: file1
File: file2
/dir/> cat file1 file2 > file3
/dir/> ls
File: file1
File: file2
File: file3
/dir/> show file3
File: file3
Content:
Very cool project! Test concat!
/dir/> rm file2
/dir/> ls
File: file1
File: file3
/dir/> cd ..
/> ls
Directory: dir
/> mkdir test
/> ls
Directory: dir
Directory: test
/> cd test
/test/> mkdir subtest
/test/> ls
Directory: subtest
/test/> cd subtest
/test/subtest/> ls
/test/subtest/> pwd
/test/subtest/
/test/subtest/> cd ..
/test/> cd ..
/> ls
Directory: dir
Directory: test
/> rm test
/> ls
Directory: dir
Directory: test
/> :q
Exit ...
ghci> :q
Leaving GHCi.
D:\File-System\src>