Useful Windows CMD Commands to Work on Files and Folders

The Windows command line (CMD) is one of the most useful utilities on a Windows PC. You can interact with the Operating System directly with the help of CMD and you can do a lot of things which are not available in the graphical user interface (GUI).

In this article, we will make you aware of many commands that you can use on the Windows CLI to work on files and folders.

Set the current drive command

To set or change the current drive, enter the drive letter followed by a colon (:), e.g.,

prompt> d:    // Change the current drive to D. The prompt changes to D:\...

D:\...> c:    // Change the current drive to C. The prompt changes to C:\...

C:\...> Program Files

Change Directory cd Command

Use command “cd new-path” to change current working directory under the current drive.

C:\> cd Program Files
// Set current directory to " Program Files " relative to current directory of the current drive

Output:

C:\Program Files>
C:\Program Files>cd Microsoft
// Set current directory to " Program Files " relative to current directory of the current drive

Output:

C:\Program Files\Microsoft>

Change directory to the root of the current drive

cd\ sets the directory to the root of current drive.

C:\.......> cd\

Output:

C:\>

Command Refer to Parent Directory

You can use “..” (double-dot) to refer to the parent directory.

C:\Program Files\Microsoft> cd ..

Output:

C:\Program Files>

Command to List All Items in Directory

By using dir command, you can list all the items of the current directory. Below given command returns all the items available in D:\TEST directory.

C:\Test>dir
CMD dir Command

Output:

Output of DIR CMD

You can use wild cards in dir for pattern matching. The wildcard “*” matches zero or more characters while “?” matches one character.

Following example lists all the files ending with “.csv”

C:\Test>dir *.csv

Following example return the files such as Example2.txt

C:\Test>dir Example?.txt

Command to Create a New Directory

By using mkdir command, you can create a new directory in the specified folder. The below given creates a new folder with the name “New_Test_Folder” in the directory D:\TEST

D:\TEST>mkdir New_Test_Folder

Command to Delete a Folder

By using rmdir command, you can delete the specified directory in the specified folder. The below given deletes “New_Test_Folder” folder of directory D:\TEST

D:\TEST>rmdir New_Test_Folder

The folder must be empty for this command to work.

Command to Delete a File

By using del command, you can delete the specified file in the specified folder. The below given deletes “Example2.txt” file of directory D:\TEST

D:\TEST>del Example2.txt

File Renaming Command on CMD

By using below given synax, you can rename rename a file.

ren filename.extension new-name.extension

Leave a Reply