Learn how to remove invalid folders or files that ends with a dot in Windows

There are a lot of formats for files, some of them starts even without a name and have a long extension as .gitignore. But if you are exploring some folders on your system and you see pretty weird files or folders whose name ends with dot(s) and you try to delete them, it won't work, which confirms that's pretty weird. Such formats are usually exploited by potential hackers, causing and generating (practically) undeletable files by the user in Windows.

By the otherside, if you are a programmer like us, you have probably made an error by running an script and creating a folder with an invalid nomenclature that anyway is created by Windows, for example with Node.js:

var fs = require("fs");

// Create invalid folders
// Create an invalid file
fs.writeFileSync('./helloworld.', 'Test content');

The previous script will create 2 undeletable (and invalid) folders for the user and a file that can't be neither read because it's invalid too. The smart ones will simply think, "simply delete the parent folder where the invalid folder are located". Well, this doesn't work as invalid folders prevent the parent folder from being removed, besides in some cases you won't be able to move the other content inside the folder.

If you are stucked with this issue and you simply don't know how to remove them, we'll show you how to do it using the command line of Windows without installing any third party software for achieving such a simple (but tedious) task.

Removing invalid folder and files

In order to remove without any problem files or folders whose name ended with a dot in Window without any external program or utility, we will need to use the command prompt of windows and execute some commands according to your case (replacing the <Folder or Filepath> with the real path to the folder or file):


If you use the second method to remove a file, you will get an exception namely "The directory name is invalid.", therefore use the first method for files and the second only for folders.

Before start executing the command, you need to know some things:

  • You cannot use rd to delete the current working directory, so change it in case you are there.
  • You cannot delete a directory that contains files, including hidden or system files, so empty it first (using the first command).

Having said that, let's get started !

1. Remove invalid files

If you are looking how to remove invalid files from your system, you will need to run the del /s command:

del /s "\\?\<File path>"

This command deletes specified files from the disk. Keep in mind that deleting files from the Windows command line does not send files to the Recycle Bin, that means that the file will be lost. However as it's invalid you shouldn't be worried about it. For example, to delete a file that can't be deleted manually with the name helloworld. and located in the path E:\Our Code World\Workspace, you could use the following command to remove it:

REM Delete the helloworld. file !
del /s "\\?\E:\Our Code World\Workspace\helloworld."

It's important to know, that if you want to delete an entire folder (using the step 2) you will need to empty the folder in case there are files inside, otherwise you'll get an exception namely "The directory is not empty". To remove all the files inside an invalid folder, use the same command, however provide the path of the folder instead:

REM Delete all files inside invalid folder asking by confirmation for every file
del /s "\\?\E:\Our Code World\Workspace\invalid-folder.."

A prompt will appear asking for confirmation for every file inside the directory.

2. Remove invalid folder

If you are looking how to remove invalid folders from your system, you can use the rd /s command:

rd /s "\\?\<Folder or Filepath>"

This command will delete the folder easily but it will ask for confirmation, just type Y and enter and the directory will be removed, for example to remove a folder:

rd /s "\\?\E:\Our Code World\Workspace\folder_invalid.."

Now you ride out of this problem and you can still work on the folder !

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.