Click here to Skip to main content
13,141,369 members (80,736 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

5.1K views
7 bookmarked
Posted 19 Dec 2015

Microsoft Reserved Words that Cannot be Used as File Name

, 19 Dec 2015
Rate this:
Please Sign up or sign in to vote.
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...


You may also be interested in...

Pro
Pro

Comments and Discussions

 
Suggestionalso... Pin
John Torjo22-Dec-15 5:00
professionalJohn Torjo22-Dec-15 5:00 
QuestionEven more to the point, they cannot appear as part of a file name. Pin
hpcoder221-Dec-15 12:53
memberhpcoder221-Dec-15 12:53 
GeneralMy vote of 5 Pin
David A. Gray19-Dec-15 20:52
memberDavid A. Gray19-Dec-15 20:52 
GeneralRe: My vote of 5 Pin
Southmountain20-Dec-15 2:34
memberSouthmountain20-Dec-15 2: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170915.1 | Last Updated 19 Dec 2015
Article Copyright 2015 by Southmountain
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid