Remembering the correct command prompts across different platforms can be confusing. To make things easier on myself I have compiled a short list of the commands and their options that are commonly used to create and delete files and folder in DOS. Including how to delete a folder and all its contents.
How to Delete a file
Deleting files from the DOS prompt is done by the del command. To use it you simply specify the single file you want deleted or the wild card pattern to match files against.
Deleting a Single file
Deleting all .jpg files
In addition to deleting files in a single directory you can delete files from subfolders as well by using the /s switch. This option says to delete files matching the pattern in a ll subfolders. I highly suggest using this switch only if you know what you are doing.
Deleting all files within a folder and its subfolders
del /s testFolder/*
The most important thing to remember is that the del command will delete files but will leave the folder structure intact.
How to delete Folders
There are two commands available to delete folders rd and rmdir. Both commands perform the same functionality so you can use which ever comes more natural to you. To delete a folder you will first have to delete its contents.
Deleting a Single Folder
rd myFolder rmdir myFolder
To delete a folder as well as its contents including files and sub folders you will use the /s switch. If you don’t want to have the command line prompt you with are you sure you want to delete each file you can also use the /q switch. This causes the command to run in quiet mode meaning it will assume y for all the prompts.
Deleting a Folder and all its contents
rd /s /q myFolder rmdir /s /q myFolder
Creating a new Directory or Folder
To create a folder you use the md or mkdir commands. When running the command simply type the name of the folder you want to create. If you want to create a sub folder as well simply pass in the full path and it will create the parent folders if they don’t exist.
Creating a single Folder
md myFolder mkdir myFolder
Creating a sub Folder and its parents
md myFolder/Folder2/Folder3 mkdir myFolder/Folder2/Folder3
To be sure creating and deleting files and folders is a command that by far is done mostly through the Operation Systems User Interface. However there are times that working from the dos prompt (command line) is a necessity, in those case simply remember del, rd, and md commands.
Comments & Questions
Add Your Comment