How to Create and Delete Files and Directories from Windows Command Prompt

Method 1 of 4:

Creating a Folder

  1. How to Create and Delete Files and Directories from Windows Command Prompt Picture 1
    Open the Command Prompt. Here are two quick ways to do so:
    1. Right-click the Start menu and select Command Prompt.
    2. Press Win+S to open the search bar, type cmd, and then click Command Prompt in the search results.
  2. How to Create and Delete Files and Directories from Windows Command Prompt Picture 2
    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.
    1. For example, if you want to create a folder on your Desktop, folder, you would type in cd desktop and press Enter.
    2. 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).
  3. How to Create and Delete Files and Directories from Windows Command Prompt Picture 3
    Type mkdir NameOfFolder at the prompt. Replace NameOfFolder with the name of the folder you wish to create.
    1. For example, to make a directory named "Homework", you would type mkdir Homework.
  4. How to Create and Delete Files and Directories from Windows Command Prompt Picture 4
    Press Enter. This runs the command to create a folder with the desired name.
Method 2 of 4:

Deleting a Folder

  1. How to Create and Delete Files and Directories from Windows Command Prompt Picture 5
    Open the Command Prompt. Here are two quick ways to do so:
    1. Right-click the Start menu and select Command Prompt.
    2. Press Win+S to open the search bar, type cmd, and then click Command Prompt in the search results.
  2. How to Create and Delete Files and Directories from Windows Command Prompt Picture 6
    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.
    1. For example, if you want to delete a folder from your Desktop, type cd desktop.
    2. 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).
  3. How to Create and Delete Files and Directories from Windows Command Prompt Picture 7
    Type rmdir /s FolderName. Replace FolderName with the name of the folder you want to delete.[1]
    1. For example, if you're trying to delete your "Homework" folder, you'd type in rmdir /s Homework here.
    2. 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").
  4. How to Create and Delete Files and Directories from Windows Command Prompt Picture 8
    Press Enter to run the command.
    1. 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]
      1. Use cd to change into the directory you want to delete.
      2. Run dir /a to view a list of all files in the directory and their attributes.
      3. 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.
      4. Type cd .. and press Enter to go back one directory.
      5. Run the rmdir /s command again to delete the folder.
  5. How to Create and Delete Files and Directories from Windows Command Prompt Picture 9
    Press y to confirm. This will permanently remove the directory.
Method 3 of 4:

Creating a File

  1. How to Create and Delete Files and Directories from Windows Command Prompt Picture 10
    Open the Command Prompt. Here are two quick ways to do this:
    1. Right-click the Start menu and select Command Prompt.
    2. Press Win+S to open the search bar, type cmd, and then click Command Prompt in the search results.
  2. How to Create and Delete Files and Directories from Windows Command Prompt Picture 11
    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.
    1. For example, if you want to create a file on the Desktop, type cd desktop and press Enter.
    2. 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).
  3. How to Create and Delete Files and Directories from Windows Command Prompt Picture 12
    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:
    1. Type type nul > filename.txt.
    2. 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).
    3. Press Enter.
  4. 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:
    1. Type copy con testfile.txt, but replace testfile with the desired file name.
    2. Press Enter.
    3. 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.
    4. Press Ctrl+Z when you're finished editing the file. This saves everything you've typed into the file.
    5. Another way to do this is to run this command: echo enter your text here > filename.txt.
  5. 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:
    1. fsutil file createnew filename.txt 1000.
    2. 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

  1. How to Create and Delete Files and Directories from Windows Command Prompt Picture 13
    Open the Command Prompt. Here are two quick ways to do this:
    1. Right-click the Start menu and select Command Prompt.
    2. Press Win+S to open the search bar, type cmd, and then click Command Prompt in the search results.
  2. How to Create and Delete Files and Directories from Windows Command Prompt Picture 14
    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.
    1. For example, if you want to delete a file from the Desktop, type cd desktop and press Enter.
    2. 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).
  3. 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.
    1. 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.
  4. How to Create and Delete Files and Directories from Windows Command Prompt Picture 15
    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.
    1. For example, to delete a text file entitled "hello", you would type del hello.txt into Command Prompt.
    2. 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").
    3. 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

May be interested

  • How to Decipher the Right Application to View an Unknown File Type on Windows VistaPhoto of How to Decipher the Right Application to View an Unknown File Type on Windows Vista
    with so many file extensions out there nowadays, its completely possible, that a few might not have a representable program existent on the 'open with' dialog box. if this is the case, this article will be for you. navigate to the proper...
  • How to Optimize Windows VistaPhoto of How to Optimize Windows Vista
    windows vista is known for taking up a lot of memory, but here are a few ways to make it run faster. click the start orb and type regedit into the search box, then press enter. if you're prompted to enter the administrator password or...
  • How to Change the Password to a Saved Wireless Network on a Windows Vista PCPhoto of How to Change the Password to a Saved Wireless Network on a Windows Vista PC
    has your wireless network password recently changed and now you need to change it on your windows vista computer so you can connect to it again? read on from step 1 below to find out this process so you'll be on the road to reconnecting....
  • How to Change Vista Icon SizePhoto of How to Change Vista Icon Size
    this article will show you how to change the size of your desktop icons in windows vista. go to your desktop (you don't need to close any programs.) you can minimize every window or just click the show desktop button in the quick launch...
  • How to Adjust Power Settings in a Windows Vista LaptopPhoto of How to Adjust Power Settings in a Windows Vista Laptop
    in windows vista, laptop owners can now choose and even make power plans to their preference. depending on whether you have to make the most of the laptop or you want a short session to watch videos or photos, choosing a power plan for...
  • How to Reduce Shadow Copy on Windows VistaPhoto of How to Reduce Shadow Copy on Windows Vista
    shadow copy, or volume snapshot device is an application interdependent with system restore that is unique to windows vista and windows 7. the shadow copy is the disk space used by system restore (up to 15% of of disk volume) which makes...