DOS Emulator using Python

In the 1980’s, when IBM introduced the IBM PC which was built with the Intel 8088 microprocessor, they needed an operating system. They approached Microsoft who provided IBM with the “Microsoft Disk Operating System”: MS-DOS.

A Disk Operating System is operated via a command prompt. The user can interact by typing key commands to maintain and operate their computer. One of the key functionality of a DOS operating system is the ability to navigate through the files and folders structure and create, rename, move or delete files and folders.

ms-dos-prompt

Try it yourself, by accessing this online DOS emulator.

In this blog post we will create a “DOS emulator” but only focusing on the navigation and maintenance of the files and folders structure. We will not implement other functionalities of a DOS.

Files & Folders Tree Structure

On a computer system, files and folders are organised using a Tree structure. For instance, let’s consider the following folder structure:
files-folders-structure

In MS-DOS, the main commands to navigate through and maintain a folder structure are:

Command Description
DIR To list the content of a directory/folder.
CD To change directory/folder. This can be used to access a subfolder or a parent folder (e.g. cd ..)
MKDIR To make a new sub-directory/folder.
DEL To delete a file or a directory/folder. This would delete the content (subfolders and files of the directory)
MOV To move a folder or a file from one folder to another.
RENAME To rename a folder or a file.

Class Diagram

We will use a File class and a Folder class to implement this tree structure:
file-folder-classes

Python Code

We have started the code for you and implemented the CD, DIR, MKDIR, DELETE and RENAME instructions as well as a HELP and a CLS (clear screen) instruction. Your task is to complete this code to create the MOVE instruction and apply it to the Folder class to let the user move a file or folder within a subfolder or the parent folder. For instance to move a file to the parent folder, the user would type the following instruction:
MOVE sea.jpg ..
Or to move a file into a subfolder called “landscapes”:
MOVE sea.jpg landscapes

Did you like this challenge?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 11

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!