A complete guide to ensuring the legality of file names under Windows
When developing file management applications, it is crucial to verify that the filenames entered by the user comply with Windows naming conventions. However, traditional regular expressions often fall short when considering various national characters.
To solve this problem, Microsoft provides a detailed guide to legal file names under Windows systems:
Character limit:
Prohibited characters: ,
, :
, /
, ,
|
, ?
, *
, integers represented between 0 and 31 characters (e.g., ASCII control characters)
Conditional restrictions: Other characters not allowed by certain file systems (for example, trailing periods or spaces)
Reserved/Prohibited DOS filenames: CON, PRN, AUX, NUL, COM0 - COM9, LPT0 - LPT9 (Note: avoid files with the extension AUX.txt)
File path:
\?\
prefix, the maximum length cannot exceed 260 characters\?\
prefix can be up to 32,000 characters long, but be aware of potential expansion issuesThe above is the detailed content of How Can I Ensure My Filenames Are Legally Valid on Windows?. For more information, please follow other related articles on the PHP Chinese website!