In this article, we are going to learn how to Delete a File, Create a Folder and Delete a Folder in Stata. We do have to work with files that are in our hard drives.
For deleting file on a hard drive, we have two commands. The “erase” command can be used if we are working on Windows, while the “rm” command would be applicable for Mac. The command for erase would look something like this,
This command erases the file that we wish to delete from our current working directory. Upon execution, this command would delete the specific file. For Mac users, the command would be,
Remember, we can delete any file on our hard drive but using the file extension is very important. Extension explains the type of file that requires to be removed. If we try to execute a command without an extension, it would not run. For example, a command for deleting a file without the extension, as following, would show that the file does not exist.
So if you want to remove the file named example, use its extension, i.e. it’s a .dta file along with the command.
We can also create a folder, along with creating a subfolder within a current folder. Let us assume that we want to create a folder called “folder2”. Our command would be,
If one wants to create a subfolder called “folder3” within the “folder2”, the command to be used should be,
Deleting a folder is also very easy. For that matter, we use the rmdir command, which stands for remove directory
However, you need to remember that this command only deletes empty folders. For example, we have a folder called “full folder” with various files, and we wish to delete it. Our command would be,
rmdir "full folder"
But it would not execute as the folder contains files and data. This command also does not execute when the folder has any kind of subfolder, may it be empty. Happy learning!