How to Create and Delete Files and Directories from Windows Command Prompt
Method 1 of 4:
Creating a Folder
- Open the Command Prompt. Here are two quick ways to do so:
- Right-click the Start menu and select Command Prompt.
- Press ⊞ Win+S to open the search bar, type cmd, and then click Command Prompt in the search results.
- Go to the desired folder. The prompt will open to C:UsersYourName by default. If you don't want to create a new folder here, type cd path_to_folder and press ↵ Enter. Replace path_to_folder with the actual folder location.
- For example, if you want to create a folder on your Desktop, folder, you would type in cd desktop and press ↵ Enter.
- If the folder isn't in your user directory (e.g., C:UsersYourName), you'll have to type in the whole path (e.g., C:UsersSomeoneElseDesktopFiles).
- Type mkdir NameOfFolder at the prompt. Replace NameOfFolder with the name of the folder you wish to create.
- For example, to make a directory named "Homework", you would type mkdir Homework.
- Press ↵ Enter. This runs the command to create a folder with the desired name.
Method 2 of 4:
Deleting a Folder
- Open the Command Prompt. Here are two quick ways to do so:
- Right-click the Start menu and select Command Prompt.
- Press ⊞ Win+S to open the search bar, type cmd, and then click Command Prompt in the search results.
- Go to the folder containing the folder you want to delete. The prompt will open to C:UsersYourName by default. If the folder you want to delete is somewhere else, type cd path_to_folder and press ↵ Enter. Replace path_to_folder with the actual folder location.
- For example, if you want to delete a folder from your Desktop, type cd desktop.
- If the folder isn't in your user directory (e.g., C:UsersYourName), you'll have to type in the whole path (e.g., C:UsersSomeoneElseDesktopFiles).
- Type rmdir /s FolderName. Replace FolderName with the name of the folder you want to delete.[1]
- For example, if you're trying to delete your "Homework" folder, you'd type in rmdir /s Homework here.
- If the folder's name has a space in it (e.g., "Homework assignments"), place the name in quotations (e.g., rmdir /s "Homework assignments").
- Press ↵ Enter to run the command.
- If you try to delete a directory that contains hidden files or folders, you'll see an error that says "The directory is not empty." In this case, you'll have to remove the "hidden" and "system" attributes from the files inside the folder. To do this:[2]
- Use cd to change into the directory you want to delete.
- Run dir /a to view a list of all files in the directory and their attributes.
- If you're still okay with deleting all of the files in the folder, run attrib -hs *. This removes special permissions from the undeletable files.
- Type cd .. and press ↵ Enter to go back one directory.
- Run the rmdir /s command again to delete the folder.
- If you try to delete a directory that contains hidden files or folders, you'll see an error that says "The directory is not empty." In this case, you'll have to remove the "hidden" and "system" attributes from the files inside the folder. To do this:[2]
- Press y to confirm. This will permanently remove the directory.
Method 3 of 4:
Creating a File
- Open the Command Prompt. Here are two quick ways to do this:
- Right-click the Start menu and select Command Prompt.
- Press ⊞ Win+S to open the search bar, type cmd, and then click Command Prompt in the search results.
- Go to the folder in which you want to create the file. The prompt will open to C:UsersYourName by default. If the folder is somewhere else, type cd path_to_folder and press ↵ Enter. Replace path_to_folder with the actual folder location.
- For example, if you want to create a file on the Desktop, type cd desktop and press ↵ Enter.
- If the folder isn't in your user directory (e.g., C:UsersYourName), you'll have to type in the whole path (e.g., C:UsersSomeoneElseDesktopFiles).
- Create an empty file of any type. If you don't want to create an empty file, skip to the next step. To create an empty file:
- Type type nul > filename.txt.
- Replace filename.txt with the desired file name and extension. Other common file extensions include ".docx" (Word document), ".png" (empty photo), ".xlsx" (Excel document), and ".rtf" (rich text document).
- Press ↵ Enter.
- Create a file containing certain text. If you don't want to create a file with certain text inside, skip to the next step. Use these steps to create a plain text file that you can type into:
- Type copy con testfile.txt, but replace testfile with the desired file name.
- Press ↵ Enter.
- Type your desired text. This is rudimentary text editor, but it's good for quick notes or code. You can use the Enter key as you type to move to the next line if you wish.
- Press Ctrl+Z when you're finished editing the file. This saves everything you've typed into the file.
- Another way to do this is to run this command: echo enter your text here > filename.txt.
- Create a file that's a certain size. If you don't want to create a file that's a specific size, skip thi step. To create a blank file based on byte size, use this command:
- fsutil file createnew filename.txt 1000.
- Replace filename with the desired file name, and 1000 with the actual number of bytes you'd like the file to be.
Method 4 of 4:
Deleting a File
- Open the Command Prompt. Here are two quick ways to do this:
- Right-click the Start menu and select Command Prompt.
- Press ⊞ Win+S to open the search bar, type cmd, and then click Command Prompt in the search results.
- Go to the folder containing the file you want to delete. The prompt will open to C:UsersYourName by default. If the file is somewhere else, type cd path_to_folder and press ↵ Enter. Replace path_to_folder with the actual folder location.
- For example, if you want to delete a file from the Desktop, type cd desktop and press ↵ Enter.
- If the folder isn't in your user directory (e.g., C:UsersYourName), you'll have to type in the whole path (e.g., C:UsersSomeoneElseDesktopFiles).
- Type dir and press ↵ Enter. This displays a list of all files in the current folder. You should see the file you want to delete in this list.
- Using Command Prompt to delete files results in the files being deleted permanently rather than being moved to the Recycle Bin. Exercise caution when deleting files via Command Prompt.
- Type del filename and press ↵ Enter. Replace filename with the full name and extension of the file you want to delete. File names include file extensions (e.g., *.txt, *.jpg). This deletes the file from your computer.
- For example, to delete a text file entitled "hello", you would type del hello.txt into Command Prompt.
- If the file's name has a space in it (e.g., "hi there"), you will place the file's name in quotations (e.g., del "hi there").
- If you get an error that says the file cannot be deleted, try using del /f filename instead, as this force-deletes read-only files.
3.5 ★ | 11 Vote
You should read it
- What is a folder The concept of a file (File) and a folder (Folder) in a computer
- How to Delete a File Using Command Prompt
- How to Copy Files in Command Prompt
- 6 ways to rename files and folders in Windows 10
- How to Open Folders in CMD
- Find and delete all .DS_Store files with a single command
- Fsutil command sparse in Windows
- How to Remove .Ds_Store Files on Mac OS X
May be interested
- How to Launch Python Files Using Windows Command Prompttoday's tipsmake will show you how to open python files using the built-in command prompt program on windows computers. in most cases, you will open the file without any problems as long as python is available on your device. if your computer uses an old version of python, or you customized it when installing and did not add the 'python' command to the 'path' variable list, proceed to add python to the 'path' variable list to be able to start. run python files through command prompt.
- How to Add and Delete Users Accounts With Command Prompt in Windowscommand prompt, which is essentially windows' version of apple's 'terminal' app, allows you to enter system-altering commands. while most user commands one might enter in command prompt are easier to carry out by simply performing the...
- How to open Command Prompt on Windows 10, 8, 7, Vista and XPcommand prompt is one of the command line interface programs used to execute commands in the windows operating system. the article will guide you how to open command prompt on windows 10, 8, 7, vista and xp.
- Add Command Prompt to Power User Menu on Windows 10on windows 10 build 14971, microsoft replaced command prompt and command prompt (admin) with windows powershell. according to microsoft, this change will bring the best command line experience to users. but in fact, users prefer to use command prompt rather than using powershell.
- Instructions for using Command Promptdeep in windows is a command-line world that is obscure. in this article, we will show you how to solve errors and make your computer more secure.
- How to find and open files with Command Promptonce you've learned how to navigate folders on windows 10, the next step is to learn how to find and open files with command prompt. this is as easy as navigating and opening a file in file explorer.
- How to Delete DLL Filesto delete unwanted or corrupt .dll files, you will need to find them by making hidden files visible, unregister them through command prompt, and then delete them manually from their source folder. your pc's dynamic link library files store...
- Open folder in Command Prompt (CMD)do you need to access a certain folder from the command prompt or windows command prompt? although it looks classic, this program is really easy to use if you know some basic commands. today's tipsmake will show you how to use the 'cd' command to open a folder in windows command prompt. besides, you will also learn great tips to immediately open the command prompt in any folder on windows file explorer.
- Tips to burn ISO file from Command Prompt on Windows 10windows 10 also allows users to burn iso files without having to use any 3rd party software or tools. actually burning iso files doesn't need to use the first integrated third tool on windows 7. all you need is a blank cd / dvd and iso file.
- 6 Cool Tricks You Can Do in Windows Command Promptcommand prompt has a ton of capabilities, and many people doubt they know what a few lines of code can do. next time you're bored with your pc, try these cool command prompt tricks for yourself.