c# - What is the maximum amount of characters or length for a Directory? -
C #? What can be a specific path for a directory of at most characters when using? > For example C: \ exam \
is 7 characters in length, what is the maximum length?
CLR has maximum 260 characters for Maxpath
In the Win32 API Library < The maximum number of characters defined by the code> MAX_PATH is defined. This setting is 260 and the same settings are used, inside the CLR BCL, hard-coded, the path reaching that amount of characters probably lead to problems (see one side below). This is the maximum good old fat and maximum for FAT32 is. On the contrary, the NTFS filesystem, by default, is used on most Windows installations, has a maximum of 32767 characters and supports Unicode (in an implementation where each letter can take 2 bytes, i.e. , UCS-2, not UTF-32). But even in the NTFS, the single path segment should not exceed 255 characters. While NTFS supports very long filenames, most applications depend on System.IO
. With the NET application, these filenames will not be able to see.
Why not 260 and 256? Because the drive specifier, the first backslash and subsequent faucet-terminator characters are not part of the length-limits. You can get this information for Windows, which you should ask for each volume individually (each volume has a different Maximum size can be).
I suppose Windows can get Linux and other OS and will be different.
As a general advice, you should not rely on any one of these numbers. Instead, hold PathTooLongException if you want to inform users that the path is too long:
try {SetCurrentDirectory (longPath); } Catch (Pathut Long Expense Act) {console. Weidline ("The name of the path was too long"); }
Note: When you exceed 260 characters, the above code will be thrown, which CLR is the limit you put on. This is not the actual limit (see the first paragraph). With Microsoft's current activation (SIS) on
.NET
, which you can not find reliable, the maximum path size is supported by CLR. If you want to receive this information from the program, then follow the path. Maxpath
use the property. However, this property is internal
which means that you can access it only through reflection and can not guarantee that it will work in whole versions, or on other BCL deployment (mono) :
// reflection fieldInfo maxPathField = typeof (path) .GetField ("Maxpath", Binding Flex. Stable | Bondfnflag.Getfield | Bondfnflag Nonpolic); // field gettor invoke, which gives 260 int MaxPathLength = (int) maxPathField.GetValue (blank);
Note: This gives you the maximum path because it is Microsoft's. Net implementation is used by maximum directory sizes, paths. There is a different value in the BCL for MX_DETETIER, but this does not happen even within BCL. If you ever make a directory equal to this size, then you will not be able to put any files inside that directory. Even worse, opening an error will cause an error (due to compulsory semi-directory aliases .
and ..
, which causes multiple APIs to crash).
Comments
Post a Comment