Home >Backend Development >C++ >How Can I Validate File Names for Legality in Windows Applications?

How Can I Validate File Names for Legality in Windows Applications?

Patricia Arquette
Patricia ArquetteOriginal
2025-01-24 16:16:13900browse

How Can I Validate File Names for Legality in Windows Applications?

How to verify the legitimacy of file names in Windows applications?

When re -naming documents, ensure that the effectiveness of the target file name is crucial. In order to compatible with international character sets and Windows complex naming agreement, a powerful verification mechanism is required.

According to MSDN's files and directory naming guidelines, the legal Windows file name usually follows the following principles:

Allowed characters:

Any character in the current code page (Unicode/Ansi 127) is allowed.

    Forbidden characters:

Special characters::, /,, |,?, * The character that represents the range between 0-31 (below ASCII space)

    The characters that the target file system is not allowed (eg, the end of the end or the space)
  • The reserved DOS device name: CON, PRN, AUX, NUL, COM0-9, LPT0-9
  • Other precautions:
File path (including file name) cannot exceed 260 characters, unless "?" Prefix.

Use the "?" In front of the unicode file pathway to 32,000 characters, but it should be noted that the expansion of the directory component may exceed this limit.

    Comply with these agreement, developers can ensure that the file name created or modified its application is valid under Windows and can respond to international character sets.

The above is the detailed content of How Can I Validate File Names for Legality in Windows Applications?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn