Skip to content

File System Project @ Functional Programming 2024-2025 @ FMI Sofia University "St. Kliment Ohridski"

Notifications You must be signed in to change notification settings

Slavi15/File-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 

Repository files navigation

File System

Overview

The principal idea behind my project implementation is to use the underlying custom-designed FileSystem structure, which conveniently represents the computer file system

FileSystem

data FileSystem =
    MkFile String String 
    | MkDirectory String [FileSystem]
    deriving (Eq, Show)
  • MkFile <name> <content> - used for creating file instances
  • MkDirectory <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

Command

data MKCommands = MkDir | Touch
    deriving (Eq, Show)

data Command = PWDCommand 
    | CDCommand 
    | LSCommand 
    | DIRCommand MKCommands
    | CATCommand 
    | RMCommand
    | SHOWCommand
    | QUITCommand
    deriving (Eq, Show)

Eval

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

Project Structure

  1. 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
  2. The logic, concerned with FileSystem manipulation is segregated into distinct code files i.e Add.hs, Remove.hs, Navigation.hs, Concat.hs

Installation

  1. Clone this repository
git clone https://github.com/Slavi15/File-System.git
# SSH: git clone [email protected]:Slavi15/File-System.git
  1. Head to src directory
cd src
  1. Load the program
ghci Main.hs
  1. Run the program
main

Commands

By default the program runs with the following file system initially:

fileSystem :: FileSystem
fileSystem = MkDirectory "/" []
  • pwd - absolute path
  • cd <path> - navigation to the provided subdirectory
  • cd .. - navigation to the parent directory
  • ls <path | empty> - prints the contents of the provided directory
  • cat <file_1> <file_2> ... <file_n> > <output_file> - combines the contents of the provided files into the output file
  • touch <path | empty> <name_1> <content_1 ++ $> <name_2> <content_2 ++ $> ... <name_n> <content_n ++ $> - creates files in the provided directory
  • mkdir <path | empty> <dir_1> <dir_2> ... <dir_n> - creates directories in the provided directory
  • rm <file_1> <file_2> ... <file_n> - removes the provided files from the current directory
  • show <file> - prints the content of the provided file in the current directory
  • :q - termination of the program

Usage

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>

About

File System Project @ Functional Programming 2024-2025 @ FMI Sofia University "St. Kliment Ohridski"

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published