How to create/delete a file using Windows command prompt?


A file on a computer stores data, information, settings, etc. On a Windows system, you can create/delete a file in so many ways, for instance, you can use Windows GUI, command line, and applications like text editors, MS Office, etc.

Using the Windows command line option for creating or removing files is comparatively faster especially when you want to create/delete multiple files.

Today in this article, I will show you how to create/ delete a file using the Windows command prompt.

How to create a file using cmd

In Windows, you can create a file in cmd by using echo or fsutil command. Usage of both commands is given below.

Create a file using the echo command

Use the following command to create a file with the echo command –

echo [Text]>filename

For example –

echo This is a sample file > testfile

You can view the content of this file by using the type command –

type testfile

create a file

Using fsutil command to create a file

If you don’t want to insert text while creating a file then you can use fsutil command for creating a file.

fsutil file createnew filename number_of_bytes

For example –

fsutil file createnew testfile 100

This will create a file with the name testfile with the size of 100 bytes.

How to delete a file from the Windows command prompt

For deleting files in cmd del command is used, the usage of this command is given below.

Suppose we have a file named testfile in our current working directory to delete it use –

del testfile

Forcefully deleting a file

Now if you are unable to delete a file with the above command then use /f with it. The option /f is used to forcefully delete a read-only file.

An example of this is given below –

del /f testfile

To know more about del command use –

help del

Conclusion

Here you have learned how to create or delete a file in the Windows command prompt.

Now if you want to ask something then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.