I have created a folder via PHP, but I made a mistake since I forgot to clear spaces. Now I cannot delete this folder.

I have found a similar issue here - look at the second answer (Quoted below), but I don't know how to rename a folder with 7-Zip.

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 Windows Explorer (both work).

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

I also tried the command line, but it does not work. My folder is named " 1 ".

I downloaded 7-Zip, and Google does not provide the help I need.

  • Try my new suggestion in my answer. – BloodPhilia Mar 13 '13 at 15:44
  • 1
    Folder names that start and end with spaces shouldn't be a problem on Win7. I was able to create a folder named " 1 " and then delete without problem using just the mkdir and rmdir commands built into cmd.exe. Is it possible the name contains other characters? E.g., are those double quotes part of the name or is it possible those spaces aren't spaces and displaying as spaces? – Nicole Hamilton Mar 13 '13 at 16:39
  • I have to agree with Nicole, here must be something else you guys are missing. Leading or trailing spaces are no problem for Windows 7 using mkdir to create a folder called " test " and normal deletion via Explorer afterwards – nixda Dec 27 '14 at 12:45
  • Great solutiion i had a file named "Invisble, Inc." which was created by Steam and belonged to the game Invisible Inc. Using 7 zip i was able to rename it and after that deleting it. – l1zard Feb 15 '16 at 18:38
up vote 5 down vote accepted

Find the item you want renamed in the main window. Then right click the file/folder in the list and click "rename".

You could also select it by clicking it once and press F2.

Edit:

Try this from the commandline:

rename "\\?\c:\<PATH HERE>\[ ]1[ ]" "<NEW FILE NAME>"

or

rename "\\?\c:\<PATH HERE>\ 1 " "<NEW FILE NAME>"

Mind you, the NEW FILE NAME doesn't take the full path, so just use the file's name. PATH HERE is just the path without the file.

  • With the first example : not found - With the second : incorrect syntax - Should I do it from the root ? – Ocelote Mar 13 '13 at 15:49
  • I used cd to go to images, and from there : \\?\C:\Websites\education-fonctionnelle\images\[ ]1[ ]" "2" => not found. \\?\C:\Websites\education-fonctionnelle\images\ 1 " "2" => incorrect syntax – Ocelote Mar 13 '13 at 15:55
  • @Ocelote, after the NEW FILE NAME, you should end with a ". I don't see this in your comment, did you use this? so: \\?\C:\Websites\education-fonctionnelle\images\[ ]1[ ]" "2" – BloodPhilia Mar 13 '13 at 15:56
  • @Ocelote, would it be okay to transfer the files to a new folder and delete the old, defective one? If so, empty the folder and try rd "\\?\C:\Websites\education-fonctionnelle\images\[ ]1[ ]" This will remove the directory. – BloodPhilia Mar 13 '13 at 16:00
  • 1
    I managed to do it again. For whoever passes by here try the command lines above. I also tried rd "\\?\C:\Websites\education-fonctionnelle\images\[ ]1[ ]" "2" (which is not correct but still, it is part of what I did) THANK YOU !!!!!!! – Ocelote Mar 13 '13 at 16:22

The answer from @Ocelot did not work on Windows Server 2008 R2. What did work was:

Open a command, change to the directory and do a "dir /x". You will see the long and the short name of the directory. You can always rename the short version as it does not contain spaces most of the time. So a ren 3839F~1.4_T whatever should be possible.

  • This is the correct answer with the current versions of the operating system. Smart, using the 8.3 file name support. I wonder why the "\\?\" hardware path was is longer supported, that is also required to support paths with a total length of more than 250-odd characters. – Tony Wall Oct 6 '15 at 9:58
  • This answer worked for me, thanks. – Derek 朕會功夫 Dec 13 '17 at 7:29

I just had a similar problem with folder "Monuments - Discography " created in linux. Windows Vista and Windows 7 couldn't recognize this folder as a valid data and when I tried to rename or remove it I got Info message saying that folder does not exist etc. The solution was to explore a dir with 7zip file manager and rename the folder by removing a white space from the end. Simple. Now I can enjoy the music once again :D

  • The OP said in their question that they do not know how to rename a folder using 7-zip. Can you please explain how to do that? Thanks. – Cfinley May 7 '15 at 18:30
  • press f2 like in windows explorer. Note you need the GUI filemanager of 7z, "7zFM.exe" – Marco van de Voort May 19 at 12:43

Are you using Windows 7? Try to do a chkdsk /f on the affected drive. It should correct illegal filenames (beware: it will move the files to a FOUND.000 folder on the root)

I just had the same problem. After using a renaming utility, I discovered that I had four files that had a leading space. I tried renaming it, but Windows coughed and said that the names couldn't be changed.

I decided to add a character (in my case, I just typed "1") in front of the leading space and I could save it (renamed). I then could rename the file by removing the character (again, in my case I just added a "1") and the aforementioned leading space without any problems.

Use the old DOS 8.3 naming method:

If the directory was called "Blah " then you could cd Blah~1 for example. Delete the contents of the folder, then at the root you could rmdir Blah~1

  • I had a folder called test and another called test <space>. rmdir TEST~1 removed the one with a space. This is a nice trick for those that do not have 7zip around. – tresf Jun 19 '17 at 17:52

Install winrar. Open it up, navigate to the file location, and you should be able to rename it. (I was having the same problem and this worked for me).

I had two files, one with a space at the end, and the other with a period at the end. Windows refused to allow me to rename or delete either. I tried doing it through Python's os module, as well, to no avail. The solution that finally worked for me was to open a command prompt (cmd.exe), cd to the folder, and then run the command:

del *.*

Of course, this means moving everything you want to keep out of the folder first.

EDIT: Sorry, reread the question and realized you are talking about a folder, not a file, so my answer really doesn't help you, but I'm going to leave it here for anyone else who has similar issues.

protected by Community Dec 7 '17 at 18:59

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.