Click here to Skip to main content
14,388,839 members

Microsoft Reserved Words that Cannot be Used as File Name

Rate this:
4.41 (8 votes)
Please Sign up or sign in to vote.
4.41 (8 votes)
19 Dec 2015CPOL
A tip that you need to know when you want to create many file names

Introduction

I am writing a small tool that needs to create lot of files with different names(9000+). Then I got one strange error message:

System.ArgumentException occurred HResult=-2147024809 Message=FileStream will not open 
Win32 devices such as disk partitions and tape drives. Avoid use of "\\.\" in the path. 
Source=mscorlib StackTrace: at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, 
Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, 
SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, 
Boolean useLongPath, Boolean checkHost) InnerException:  

I did some research and found out the reason. I have listed the results here to share with you. Hope it will save you some time in the future.

Cause

Microsoft has reserved the following words that cannot be used as file names:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.?

Reference

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Southmountain
Software Developer
United States United States
turns good thoughts into actions...


Comments and Discussions

 
Suggestionalso... Pin
John Torjo22-Dec-15 6:00
professionalJohn Torjo22-Dec-15 6:00 
QuestionEven more to the point, they cannot appear as part of a file name. Pin
hpcoder221-Dec-15 13:53
Memberhpcoder221-Dec-15 13:53 
GeneralMy vote of 5 Pin
David A. Gray19-Dec-15 21:52
MemberDavid A. Gray19-Dec-15 21:52 
GeneralRe: My vote of 5 Pin
Southmountain20-Dec-15 3:34
MemberSouthmountain20-Dec-15 3:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Tip/Trick
Posted 19 Dec 2015

Tagged as

Stats

7.9K views
7 bookmarked