Tuesday, November 22, 2005

List of Invalid Keyboard Characters for a Windows XP filename

What keyboard characters are not valid for a Windows XP filename?

This has come up several times over the years during my programming tasks when I have tried to automatically generate a filename based on some collection of data. It seems a good time to document this relatively simple question for my future reference as well as yours.

The keyboard characters that cannot be used in a Windows XP filename are:

* Asterisk

Pipe (vertical bar)

\ Back slash

/ Forward slash

: Colon

" Quote

< Less Than

> Greater Than

? Question mark

Hope that helps!
Joe Kunk


Greg O'Neil said...

Is your list possibly derived from a pre-XP OS version (dos, 3.1, etc.)?

Periods are okay and are one of the most used characters, appearing in all filenames except for non-typed files: f.txt, p.html, etc.

And, they're use is not limited to separating the file type with the filename prefix. f1.txt.jpg seems to work perfectly well. Thanks.

dwmsyron said...

The list is correct except for the period. Here's more information:


That doesn't specifically mention XP, but it looks like things haven't changed much.

Joe Kunk said...

Thanks for pointing out that a period should not have been included in the list. I have made the correction to the post.

Thanks again,

jimjamjo said...

Function InvalidChars(ByVal PathIn As String) As String
' Get a list of invalid path characters.
Dim invalidFileNameChars As Char() = Path.GetInvalidFileNameChars

' Display each invalid character to the console.
Dim iC As Char
For Each iC In invalidFileNameChars
If InStr(PathIn, iC) > 0 Then
PathIn = Replace(PathIn, iC, "_")
Console.WriteLine("Replacing invalid character in filename" & iC)
End If
Next iC

InvalidChars = PathIn
End Function

cheap oem software download said...

Clearly, I thank for the help in this question.

Simun said...

Maybe I am wrong, but isn't the equals sign another invalid character?

I know this comment is about 7 years late. I was looking for info as I encountered a file with a filename containing an equals sign followed by a dot (with no extension) which I could not rename/delete and chkdsk wouldn't correct. I achieved success utilising 7zip to rename and delete the file

Simun said...

Sorry, I should have checked what dwmsyron had said...

Jatin said...
This comment has been removed by the author.
Jatin said...

Check this for complete list of file naming conventions in Windows.