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

Author: Lewis Jackson
Date Of Creation: 13 May 2021
Update Date: 1 July 2024
Anonim
Windows command prompt tutorial 2 - making folders, deleting folders, creating and deleting files
Video: Windows command prompt tutorial 2 - making folders, deleting folders, creating and deleting files

Content

This article guides you how to use the Command Prompt on Windows to create and delete files and folders (also known as directories). Files you create from the Command Prompt can be edited and managed using apps on Windows, including File Manager and a text editor.

Steps

Method 1 of 4: Create a directory

  1. Open Command Prompt in two quick ways:
    • Right-click the Start menu and select Command Prompt.
    • Press ⊞ Win+S To open the search bar, type cmd, then click Command Prompt in the search results.

  2. Access the required directory. 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 CD path_to_folder and press ↵ Enter. Instead path_to_folder by the path of the directory.
    • For example, if you wanted to create a folder on the Desktop, you'd import cd desktop and press ↵ Enter.
    • If the folder is not in the user directory (such as C: Users Your name), you will have to enter the path (for example: C: Users Name Desktop Files).

  3. Import mkdir NamOfFolder into the Command Prompt. Instead NameOfFolder equal to the name of the folder you want to create.
    • For example, to create a folder called "Homework", you would type mkdir Homework.

  4. Press ↵ Enter. This will prompt the Command Prompt to create a folder with the desired name. advertisement

Method 2 of 4: Delete Directory

  1. Open Command Prompt in two quick ways:
    • Right-click the Start menu and select Command Prompt.
    • Press ⊞ Win+S to open the search bar, type cmd and click Command Prompt in the search results.
  2. Go to the folder containing the folder you want to delete. Command Prompt window will display the command C: Users Your name by default. If you want to delete another folder, you will import CD path_to_folder and press ↵ Enter. Instead path_to_folder by the path of the directory.
    • For example, if you want to delete a folder from the Desktop, type cd desktop.
    • If the folder is not in the user directory (such as C: Users Your name) you will have to enter the entire path (for example: C: Users Name Desktop Files).
  3. Import rmdir / s FolderName. Instead FolderName by the name of the folder you want to delete.
    • For example, if you wanted to delete the "Homework" folder, you'd enter rmdir / s Homework here.
    • If the folder name has a space (such as "Homework assignments"), enclose the name in quotation marks (for example: rmdir / s "Homework assignments").
  4. Press ↵ Enter to execute the command.
    • If you want to delete a directory containing a hidden file or directory, you will see the error message "The directory is not empty". In this case, you will have to remove the "hidden" and "system" properties of the files inside the directory. Please do as follows:
      • Use CD to change the folder you want to delete.
      • Order execution get out to see a list of all the files in the directory and their properties.
      • If you still can't delete all the files in the directory, execute the command attrib -hs *. This removes special permissions from files that cannot be deleted.
      • Import CD.. and press ↵ Enter to go back to the previous folder.
      • Order execution rmdir / s again to delete the directory.
  5. Press y To confirm. This will permanently delete the folder. advertisement

Method 3 of 4: Create the file

  1. Open Command Prompt in two quick ways:
    • Right-click the Start menu and select Command Prompt.
    • Press ⊞ Win+S to open the search bar, type cmd then click Command Prompt in the search results.
  2. Go to the directory where you want to create the file. Command Prompt window will display the command C: Users Your name by default. If you want to use another folder, you will import CD path_to_folder and press ↵ Enter. Instead path_to_folder by the path of the directory.
    • For example, if you want to create a file on the Desktop, enter cd desktop and press ↵ Enter.
    • If the folder is not in the user directory (such as C: Users Your name) you will have to enter the entire path (for example: C: Users Name Desktop Files).
  3. Create empty file in any format. If you don't want to create an empty file go to the next step. An empty file will be created in the following way:
    • Type nul> type filename.txt.
    • Instead filename.txt with the filename and the extension you like. Other popular extensions include ".docx" (Word documents), ".png" (empty image files), ".xlsx" (Excel documents), and ".rtf" (for documents). has a basic format).
    • Press ↵ Enter.
  4. Create text file. If you don't want to create a text file, go to the next step. Use the following steps to create a plain text file in which you can import content:
    • Type copy child testfile.txt, but instead testfile with the filename you like.
    • Press ↵ Enter.
    • Enter content as you like. This is a rudimentary text editor, but still effective for coding or taking quick notes. You can use the key Enter while editing to enter text on the next line if desired.
    • Press Ctrl+Z when you are finished editing the file. This is the action to save all imported content to the file.
    • Another way to do this is entering commands echo enter content here > file name.txt.
  5. Create files of a certain size. If you don't want to size the file, skip this step. To create an empty file by byte size, execute the following command:
    • fsutil file createnew filename.txt 1000.
    • Instead filename with the name you want, and replace 1000 equal to the number of bytes to create for the file.
    advertisement

Method 4 of 4: Delete files

  1. Open Command Prompt in two quick ways:
    • Right-click the Start menu and select Command Prompt.
    • Press ⊞ Win+S to open the search bar, type cmd then click Command Prompt in the search results.
  2. Go to the folder containing the file you want to delete. Command Prompt window will display the command C: Users Your name by default. If you want to use another folder, you will import CD path_to_folder and press ↵ Enter. Instead path_to_folder by the path of the directory.
    • For example, if you want to create a file on the Desktop, enter cd desktop and press ↵ Enter.
    • If the folder is not in the user directory (such as C: Users Your name) you will have to enter the entire path (for example: C: Users Name Desktop Files).
  3. Import dir and press ↵ Enter to open a list of all files in the current directory. You will see the file you want to delete in this list.
    • Files deleted with the Command Prompt are permanently deleted instead of being moved to the Recycle Bin. Therefore, you should act very carefully when deleting files using Command Prompt.
  4. Import del filename and press ↵ Enter. Instead 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 type del hello.txt into the Command Prompt.
    • If the filename has spaces (eg "hi there"), enclose the filename in quotation marks (such as del "hi there").
    • If you get a message that the file cannot be deleted, use the command del / f filename instead, because this command is used to delete read-only files.
    advertisement

Warning

  • Files deleted with the Command Prompt are permanently deleted instead of being moved to the Recycle Bin. Therefore, you should act very carefully when deleting files using Command Prompt.