How to delete a folder containing trailing spaces

17

5

I have a bunch of folders on my hardrive that have trailing spaces in them (I have no idea how they got there). I need to rename and/or delete them, but Windows won't allow me to do this. Is there a way around this problem?

I've tried to delete it via the commandline, but that did not work.

I'm running Windows XP, and it's an NTFS drive.

SuperFurryToad

Posted 2010-10-11T14:48:14.343

Reputation: 555

Answers

23

First try some quoting:

rd "my folder   "

Then UNC paths:

rd "\\.\C:\temp\my folder   "

Then try adding a trailing [back]slash:

rd "my folder   \"
rd "\\.\C:\temp\my folder   \"

Then 8.3 names (if they are enabled on your system):

rd myfold~1

Then a Linux LiveCD:

rmdir "/media/blahblah/temp/my folder   "

user1686

Posted 2010-10-11T14:48:14.343

Reputation: 283 655

+1 for suggesting also The Linux solution – Sekhemty – 2014-12-27T13:01:41.480

3Backslash method worked for me on Windows 10 – KnightHawk – 2016-12-21T15:57:58.563

3Deleting using the 8.3 names worked. Thanks – SuperFurryToad – 2010-10-11T15:18:13.250

Good ol DOS legacy. – surfasb – 2011-04-02T15:41:38.673

"mydomain.com " as a folder. DOS thought the 8.3 filename was "mydoma~1.com". But it worked. Super thanks! – Coomie – 2011-12-08T06:09:38.987

17

I had the same problem, in Windows 7 x64, and none of the command-line solutions worked here.

What fixed it for me:

  • Rename the folder using 7-Zip
  • Delete, either using 7-Zip or Explorer (both work)

Note that deleting the folder in 7-Zip before renaming it was impossible.

larskinn

Posted 2010-10-11T14:48:14.343

Reputation: 171

1Thanks this was the only method that worked for me on a folder mounted from a remote file server – Anigel – 2015-04-02T10:23:54.627

wow, that really worked surprisingly well for me - thanks for the less traditional suggestion? – matt lohkamp – 2015-08-10T04:41:43.093

17-Zip worked for be on a 2008R2 trailing folder that I could not delete. – None – 2012-05-22T17:34:10.313

4

windows 7

I was having issues getting rid of a folder. "C:\Users\Rob\Desktop\Music\ A k o n "

This is what finally worked for me: I opened up the cmd prompt in the Music folder (shift right click, open command window here)

then typed in the following command

rd " A k o n \"

notice the back slash.

beginning spaces and trailing spaces really mess crap up. I spent at least 2 hours searching for a solution.

Thank you grawity for posting the solution.

Rob Moore

Posted 2010-10-11T14:48:14.343

Reputation: 349

1

Then the DOS name:

dir /x
rd FOLDER~1

Then the (UNC?) name which I'm not sure how to find or what exactly it looks like:

rd \Device\HarddiskVolume1\temp\folder
rd \\?\Device\HarddiskVolume1\temp\folder

Hello71

Posted 2010-10-11T14:48:14.343

Reputation: 7 636

System-local UNC paths start with \\.\ for devices and \\?\ for files (official doc); using \\?\C:\ is often enough.

– user1686 – 2010-10-12T18:21:49.647

1

RoboCopy seems particularly good at addressing folders/paths verbatim, so you could make an empty folder alongside the parent of the folder that has your erroneously named folder and then copy the empty folder to be the parent folder path and specify the PURGE option, which will purge the other entries in the destination folder. Hopefully you will also ensure that only bad folders are there

In summary, you want to copy 0 files into the folder that houses your bad folder, and specify /purge so that the operation clears out anything else in the folder (including your bad folder)

Confused? Then an example will surely help. Suppose you have:

C:\path\leading-to-a\folder-with-space \

Run these commands:

cd c:\path\
mkdir empty
robocopy empty leading-to-a /purge

robocopy will copy the empty folder to the leading-to-a folder, and purge the other entries in the leading-to-a folder, one of which is your folder with a trailing space:


  ROBOCOPY     ::     Robust File Copy for Windows

 Started : Thu Jan 01 00:00:00 1970

  Source : C:\path\empty\
    Dest : C:\path\leading-to-a\

   Files : *.*

 Options : *.* /COPY:DAT /PURGE /R:1000000 /W:30

                          0    C:\path\empty\
       *EXTRA Dir        -1    C:\path\leading-to-a\folder-with-spaces \

              Total    Copied   Skipped  Mismatch    FAILED    Extras
   Dirs :         1         0         1         0         0         1
  Files :         0         0         0         0         0         0
  Bytes :         0         0         0         0         0         0
  Times :   0:00:00   0:00:00                       0:00:00   0:00:00

  Ended : Thu Jan 01 00:00:00 1970

Warning:

Make sure that anything you want to keep is moved out of the leading-to-a folder first!

Caius Jard

Posted 2010-10-11T14:48:14.343

Reputation: 235

0

Use WinRAR to find that file and rename it without the space at the end. You should be able to delete it!

Eunice

Posted 2010-10-11T14:48:14.343

Reputation: 11

0

Boot with a live CD of Ubuntu, and you will be able to delete anything you want.

To boot with the CD you should change the boot order in your BIOS settings.

hazarks

Posted 2010-10-11T14:48:14.343

Reputation: 11