Delete filename with trailing space..

J

Jake

Help...

How do I delete a file / folder in XP which has a trailing space...?

regards jake
 
A

Andrew McLaren

How do I delete a file / folder in XP which has a trailing space...?


Hi Jake

Put quotes around the file name. For example from a command line:


C:\SOMEDIR>del "this is a file with a trailing space "

or

C:\>rmdir "this is a folder with a trailing space "


Note the trailing space, in these commands :)

Hope it helps,

Andrew
 
P

Pegasus [MVP]

Jake said:
Help...

How do I delete a file / folder in XP which has a trailing space...?

regards jake

AFAIK, Windows allows file or folder names with *embedded* spaces but not
with *trailing* spaces. How exactly did you work out that you had a name
with a trailing space?
 
A

a

Pegasus said:
AFAIK, Windows allows file or folder names with *embedded* spaces but not with *trailing* spaces.

Huh? Of course files and folders can have spaces at their start or end.
How exactly did you work out that you had a name with a trailing space?

By seeing the blank space in the focus rectangle when selected.
 
P

Pegasus [MVP]

a said:
Huh? Of course files and folders can have spaces at their start or end.


By seeing the blank space in the focus rectangle when selected.

This can be deceptive. The white space could be $FF. It looks the same as a
space but it isn't.
 
A

Andrew McLaren

AFAIK, Windows allows file or folder names with *embedded* spaces but
not with *trailing* spaces. How exactly did you work out that you had a
name with a trailing space?

With respect ... actually, NTFS has no problem creating a file with a
trailing space in the name. However Windows Explorer, CMD.EXE and
OS-supplied utilities will usually trim any trailing spaces from a file
name when they manipulate a file. So, yes: a trailing space is rare. But
any app can decide to do:

hFile = CreateFile("My funnny file " // file name
<...> // other params
FILE_ATTRIBUTE_NORMAL, // normal file
NULL);

....and create a file with a trailing space in its name.

Trailing spaces are explicitly deprecated in the Windows SDK's file
naming convention guidelines; but there's nothing to actually stop
someone from doing it.

You are correct that the U+00A0 "No break space" char can also look like
a space, and is indeed legal at the end of file names.

Apologies for being a pedantic pain-in-the-butt, but ... I get all
pedantic, sometimes :)

Cheers

Andrew
 
P

Pegasus [MVP]

Andrew McLaren said:
With respect ... actually, NTFS has no problem creating a file with a
trailing space in the name. However Windows Explorer, CMD.EXE and
OS-supplied utilities will usually trim any trailing spaces from a file
name when they manipulate a file. So, yes: a trailing space is rare. But
any app can decide to do:

hFile = CreateFile("My funnny file " // file name
<...> // other params
FILE_ATTRIBUTE_NORMAL, // normal file
NULL);

...and create a file with a trailing space in its name.

Trailing spaces are explicitly deprecated in the Windows SDK's file naming
convention guidelines; but there's nothing to actually stop someone from
doing it.

You are correct that the U+00A0 "No break space" char can also look like a
space, and is indeed legal at the end of file names.

Apologies for being a pedantic pain-in-the-butt, but ... I get all
pedantic, sometimes :)

.. . . which goes to show that just because I am unable to do a certain thing
does not mean that it can't be done. Thanks for the clarification!
 
J

Jose

Help...

How do I delete a file / folder in XP which has a trailing space...?

regards jake

How did you determine that the file / folder has a trailing space, how
are you trying to delete it (Windows Explorer?), do you get any kind
of error message stating the attempt failed and if you do, what is the
message?
 
A

a

Pegasus said:
This can be deceptive. The white space could be $FF. It looks the same as a space but it isn't.

It's not $FF, it's $20. I did it myself via my own application. (It was actually
a bug in my app that led to two filenames having a leading space, due to a bad
crop of their names).
 
J

John John - MVP

Jake said:
Help...

How do I delete a file / folder in XP which has a trailing space...?

At a command prompt:

del "\\?\c:\path_to_file_that contains a trailing space.txt "

To avoid path errors it's easier to grab the file with Windows Explorer
and then drop it at the command prompt, type the partial command:

del \\?\

then drop the grabbed file to the prompt. Pay attention to the path's
"quotation marks".

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top