How to delete a file with a name that is too long

Recently, we had some files on a Windows 2012 server that have file names that are too long. The UNC path length would be okay if the file name was not too long. And as it would happen on this partition we left the short name 8.3 option disabled (as recommended by Microsoft). So, how do we delete these files?

Adding this to lovely mix are the differences between PowerShell and the old school Command Line (i.e.; cmd.exe). The cmd.exe shell has a few options that can help us. For example, if you do a dir /x you can get a listing of the short name for a file (if the partition has that option enabled).

Two other easy to use options are to delete the directory that contains the file whose name is too long.

1. In the cmd.exe to use: rmdir /S /Q the_dir_to_delete

2. This other option uses robocopy. You do have robocopy or Richcopy installed, right? In the cmd.exe do:

  1. mkdir empty_dir
  2. robocopy empty_dir the_dir_to_delete /s /mir
  3. rmdir empty_dir
  4. rmdir the_dir_to_delete