Paul Taylor
Paul Taylor

Reputation: 13160

Is the 255 char limit for filenames on Windows and Unix the whole path, or part of path?

Is the 255 char limit for filenames on Windows NTFS and Unix the whole path, or part of path ?

i.e given c:\part1\part2 have just part1 and part2 got to be less than 255 or is it C:\ + part1 + part2

And whats the rules on Unix ?

Upvotes: 4

Views: 6663

Answers (3)

Jim Stewart
Jim Stewart

Reputation: 17353

In addition to the answers above, you also have to account for the filesystem being used (ext2, etc.). There's no standard answer for Unix. Linux is generally 255 per component and either 4096 for the full path, or unlimited for the path. Other Unix variants use different limits. OSX with HFS+ is 255 filename and either 1024 or unlimited path (I can't find a definitive answer). Unless you're positive you only have to worry about Linux, you'll probably want to keep the overall path low just to be sure. It's not a bad idea to limit the entire path to 255 if possible. You may also need to consider that filesystems can be network-mounted, and NFS, SMB, etc. have their own limits.

The short answer for Unix is that there is no short answer nor is there a standard, and both the operating system and the underlying filesystem impose restrictions.

Upvotes: 2

itisravi
itisravi

Reputation: 3571

On a Linux system, part1 and part2 should both be 255 (i.e. FILE_MAX) or less and the whole path should be 4096 (i.e.PATH_MAX) or less. PATH_MAX usage has flaws as explained here.

Upvotes: 1

On Windows part 1 and part2 should be both 255 or less, and the whole c:\part1\part2 should be 260 or less. There's a way to have longer file names and paths on WinNT kernel (Windows 2000, XP and later) but this requires that applications which access such file explicitly support such filenames, so in vast majority of cases you can treat 255/260 limit as a hard limit.

Upvotes: 3

Related Questions