This Node.js application simulates a directory management system where you can create, move, and delete directories. It reads a sequence of commands and outputs the resulting directory structure.
-
Ensure you have Node.js installed on your machine. You can download it from here.
-
Clone or download this repository.
-
Open a terminal and navigate to the directory where the code is located.
-
Run the following command to execute the directory management script:
node directories.js [filename]
Replace
[filename]
with the name of the file containing your commands. If no filename is provided, it will default tocommands.txt
.
The application understands the following commands:
CREATE <directory>
: Creates a new directory.MOVE <source> <destination>
: Moves a directory from the source path to the destination path.DELETE <directory>
: Deletes a directory.LIST
: Lists the current directory structure.
Consider the following input:
CREATE fruits
CREATE vegetables
CREATE grains
CREATE fruits/apples
CREATE fruits/apples/fuji
LIST
CREATE grains/squash
MOVE grains/squash vegetables
CREATE foods
MOVE grains foods
MOVE fruits foods
MOVE vegetables foods
LIST
DELETE fruits/apples
DELETE foods/fruits/apples
LIST
The expected output would be:
CREATE fruits
CREATE vegetables
CREATE grains
CREATE fruits/apples
CREATE fruits/apples/fuji
LIST
fruits
apples
fuji
grains
vegetables
CREATE grains/squash
MOVE grains/squash vegetables
CREATE foods
MOVE grains foods
MOVE fruits foods
MOVE vegetables foods
LIST
foods
fruits
grains
vegetables
squash
DELETE fruits/apples
Cannot delete fruits/apples - fruits does not exist
DELETE foods/fruits/apples
LIST
foods
fruits
grains
vegetables
squash