How to Create and Delete Files or Folders from Windows Command Prompt

This article shows you how to use Command Prompt on Windows to create and delete files and folders (also known as directories). Files you create from Command Prompt can be edited and managed with Windows applications, including File Manager and text editors.

Create folder

How to Create and Delete Files or Folders from Windows Command Prompt Picture 1How to Create and Delete Files or Folders from Windows Command Prompt Picture 1

Open Command Prompt in two quick ways:

Right-click the Start menu and select Command Prompt .

Press ⊞ Win+ Sto open the search bar, type cmd, then click Command Prompt in the search results.

How to Create and Delete Files or Folders from Windows Command Prompt Picture 2How to Create and Delete Files or Folders from Windows Command Prompt Picture 2

Access the required folder. The Command Prompt window will display the command C:Users Your name by default. If you don't want to create a new folder here, type and press . Replace path_to_folder with the folder's path.cd path_to_folder ↵ Enter

For example, if you want to create a folder on the Desktop, you would type cd desktopand press ↵ Enter.

If the directory is not in the user directory (such as C:Users Your Name ), you will have to enter the path as well (for example: C:UsersTênDesktopFiles).

How to Create and Delete Files or Folders from Windows Command Prompt Picture 3How to Create and Delete Files or Folders from Windows Command Prompt Picture 3

Enter Command Prompt.mkdir NamOfFolder Replace NameOfFolder with the name of the folder you want to create.

For example, to create a folder named "Homework", you would enter mkdir Homework.

How to Create and Delete Files or Folders from Windows Command Prompt Picture 4How to Create and Delete Files or Folders from Windows Command Prompt Picture 4

Press ↵ Enter. This tells Command Prompt to create a folder with the name you want.

Delete folder

How to Create and Delete Files or Folders from Windows Command Prompt Picture 5How to Create and Delete Files or Folders from Windows Command Prompt Picture 5

Open Command Prompt in two quick ways:

Right-click the Start menu and select Command Prompt .

Press ⊞ Win+ Sto open the search bar, type cmdand click Command Prompt in the search results.

How to Create and Delete Files or Folders from Windows Command Prompt Picture 6How to Create and Delete Files or Folders from Windows Command Prompt Picture 6

Access the folder containing the folder you want to delete. The Command Prompt window will display the command C:Users Your name by default. If you want to delete another folder, you will enter and press . Replace path_to_folder with the folder's path.cd path_to_folder ↵ Enter

For example, if you want to delete a folder from the Desktop, enter cd desktop.

If the directory is not in the user directory (such as C:Users Your Name ), you will have to enter the entire path (e.g. C:UsersTênDesktopFiles).

How to Create and Delete Files or Folders from Windows Command Prompt Picture 7How to Create and Delete Files or Folders from Windows Command Prompt Picture 7

Import .rmdir /s FolderName Replace FolderName with the name of the folder you want to delete.

For example, if you want to delete the "Homework" folder, you would enter it rmdir /s Homeworkhere.

If the folder name contains spaces (such as "Homework assignments"), you would enclose the name in quotation marks (for example: rmdir /s "Homework assignments").

How to Create and Delete Files or Folders from Windows Command Prompt Picture 8How to Create and Delete Files or Folders from Windows Command Prompt Picture 8

Press ↵ Enterto execute the command.

If you want to delete a folder that contains hidden files or folders, you will see the error message "The directory is not empty". In this case, you will have to delete the "hidden" and "system" attributes of the files inside the folder. Do the following:

Used cdto change the folder you want to delete.

Execute the command dir /ato view a list of all files in the directory and their properties.

If you still cannot delete all the files in the directory, execute the command attrib -hs *. This removes special access permissions from files that cannot be deleted.

Enter cd .and press ↵ Enterto return to the previous folder.

Execute the command rmdir /sagain to delete the folder.

How to Create and Delete Files or Folders from Windows Command Prompt Picture 9How to Create and Delete Files or Folders from Windows Command Prompt Picture 9

Press yto confirm. This will delete the folder permanently.

Create file

How to Create and Delete Files or Folders from Windows Command Prompt Picture 10How to Create and Delete Files or Folders from Windows Command Prompt Picture 10

Open Command Prompt in two quick ways:

Right-click the Start menu and select Command Prompt .

Press ⊞ Win+ Sto open the search bar, type cmdthen click Command Prompt in the search results.

How to Create and Delete Files or Folders from Windows Command Prompt Picture 11How to Create and Delete Files or Folders from Windows Command Prompt Picture 11

Go to the folder where you want to create the file. The Command Prompt window will display the command C:Users Your name by default. If you want to use another folder, you will enter and press . Replace path_to_folder with the folder's path.cd path_to_folder ↵ Enter

For example, if you want to create a file on the Desktop, enter cd desktopand press ↵ Enter.

If the directory is not in the user directory (such as C:Users Your Name ), you will have to enter the entire path (e.g. C:UsersTênDesktopFiles).

How to Create and Delete Files or Folders from Windows Command Prompt Picture 12How to Create and Delete Files or Folders from Windows Command Prompt Picture 12

Create empty files in any format. If you don't want to create an empty file, go to the next step. The empty file will be created in the following way:

Type type nul > filename.txt .

Replace filename.txt with the file name and extension you like. Other common extensions include ".docx" (Word document), ".png" (empty image file), ".xlsx" (Excel document), and ".rtf" (for text has basic format).

Press ↵ Enter.

Create text files. If you don't want to create a text file, go to the next step. Use the following steps to create a raw text file into which you can import content:

Type , but replace testfile with the filename you prefer.copy con testfile.txt

Press ↵ Enter.

Enter content as you like. This is a rudimentary text editor, but still effective for writing code or taking quick notes. You can use the key Enterwhile editing to enter text on the next line if you like.

Press Ctrl+ Zwhen you finish editing the file. This operation saves all imported content to the file.

Another way to do this enter the .echo nhập nội dung tại đây > tên tập tin.txt

Create a file of a certain size. If you don't want to resize the file, skip this step. To create an empty file by byte size, you would execute the following command:

fsutil file createnew filename.txt 1000.

Replace filename with the name you want, and replace 1000 with the number of bytes needed for the file.

Delete files

How to Create and Delete Files or Folders from Windows Command Prompt Picture 13How to Create and Delete Files or Folders from Windows Command Prompt Picture 13

Open Command Prompt in two quick ways:

Right-click the Start menu and select Command Prompt .

Press ⊞ Win+ Sto open the search bar, type cmdthen click Command Prompt in the search results.

How to Create and Delete Files or Folders from Windows Command Prompt Picture 14How to Create and Delete Files or Folders from Windows Command Prompt Picture 14

Access the folder containing the file you want to delete. The Command Prompt window will display the command C:Users Your name by default. If you want to use another folder, you will enter and press . Replace path_to_folder with the folder's path.cd path_to_folder ↵ Enter

For example, if you want to create a file on the Desktop, enter cd desktopand press ↵ Enter.

If the directory is not in the user directory (such as C:Users Your Name ), you will have to enter the entire path (e.g. C:UsersTênDesktopFiles).

Enter dirand press ↵ Enterto open a list of all files in the current folder. You will see the file you want to delete in this list.

Files deleted using Command Prompt will be permanently deleted instead of being moved to the Recycle Bin. Therefore, you should be very careful when deleting files using Command Prompt.

How to Create and Delete Files or Folders from Windows Command Prompt Picture 15How to Create and Delete Files or Folders from Windows Command Prompt Picture 15

Enter and press .del filename↵ Enter Replace filename with the full name and extension of the file you want to delete. The file name includes the file extension (such as *.txt, *.jpg). This will delete the file from your computer.

For example, to delete a text file named "hello", you would enter del hello.txtCommand Prompt.

If the filename contains spaces (e.g., "hi there"), you would enclose the filename in quotes (e.g., del "hi there").

If you receive a message that the file cannot be deleted, use the command , as this command is used to delete read-only files.del /f filename instead

4.5 ★ | 2 Vote