Mastering basic file management at the Windows Command Prompt is essential for coding, scripting, and efficient system tasks. This guide teaches you how to create and delete files and directories directly from the command line, allowing seamless interaction with Windows apps and automation workflows.
How to create and delete files and directories in Command Prompt
Follow these step-by-step methods to create, fill, size, and remove files and folders using Windows Command Prompt.
Method 1: Creating a file
- Press Win + S to open search, typecmd, and selectCommand Prompt.
- Navigate to your target directory by typing cd path_to_directory (e.g., cd Desktop) and pressing Enter. Use the full path if needed, like C:\Users\YourName\Desktop.
- To create an empty file, typetype nul > filename.txt (replace filename.txt with your desired name) and press Enter.
- To create a file with content:
- Typecopy con filename.txt and press Enter.
- Type your text (use Enter for new lines).
- Press Ctrl + Z, then Enter to save. Alternatively, typeecho your text > filename.txt.
- To create a blank file of specific size, typefsutil file createnew filename.txt 1000 (replace size in bytes) and press Enter.
Method 2: Deleting a file
- Press Win + S to open search, typecmd, and selectCommand Prompt.
- Navigate to the directory with cd path_to_directory (e.g., cd Desktop) and press Enter.
- Typedir and press Enter to list files.
- Typedel filename.txt (include extension; use quotes for spaces like del “file name.txt”; use del /f filename.txt for read-only) and press Enter.
Method 3: Creating a folder
- Press Win + S to open search, typecmd, and selectCommand Prompt.
- Navigate to the target directory with cd path_to_directory (e.g., cd Desktop) and press Enter.
- Typemkdir DirectoryName (use quotes for spaces) and press Enter.
Method 4: Deleting a folder
- Press Win + S to open search, typecmd, and selectCommand Prompt.
- Navigate to the parent directory with cd path_to_directory (e.g., cd Desktop) and press Enter.
- Typermdir /s DirectoryName (use quotes for spaces) and press Enter.
- PressY then Enter to confirm. Warning: This permanently deletes the folder and all contents.
- If it fails due to hidden/system files:
- Typecd DirectoryName.
- Typedir /a to view all files.
- Typeattrib -hs * to remove attributes.
- Typecd .., then retry rmdir /s DirectoryName and confirm with Y.
Command Prompt file management builds foundational skills for automation and scripting in tools like PowerShell or batch files. It enables quick tasks without graphical interfaces, saving time during development or system administration.
These commands are crucial for programmers, as they integrate directly into code workflows for testing, data handling, and deployment. Mastering them enhances efficiency and prepares you for advanced command-line environments in Linux or servers, boosting your technical versatility.








