简体   繁体   中英

Can an empty string be a legal file name?

I would like to know if an empty string is a legal file name in any of the commonly used operating and file systems.

I guess not - but I can only guess.

Context: If the empty string is a universally illegal filename, it would be a simple to use test case for non-existent files. However, tests may err if there are situations where the empty string is a valid file name.

Perhaps unfortunately for you, it depends ! Different filesystems firmly disagree about what is a "legal file name"! (a frequent source of confusion is that some are case-insensitive)

I suspect that some filesystem you will encounter will support it, but that case may not really matter for you

Your best bet would be to explicitly prevent silly names in your program (see below) or to try testing on a subset of filesystems with known versions

Some helpful information


However, for program design, I would instead try to regulate filenames to exact sets of characters (directly using a uuid or at least a regex), explicitly prevent empty string, and just include whatever "name" users cook up to trouble your programs and filesystem in a field in a file you control and creates

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM