Jump to content
Macro Express Forums

Maximum file name length with UNC share


Recommended Posts

Can someone explain to me the logic of the maximum number of characters on an NTFS volume thru a UNC share? I have macros that file things for users and I find the need to test their name strings to make sure they are not too long.

 

On an NTFS volume the maximum name length is 256 without the "C:\" and null character at the end of the file name. I have verified this using MEP. I was told that this limitation is on the volume itself and therefore the overall path would not include the \\Machine\Share\ in the character count but rather whatever path exists on the server behind the share. However I am finding this is not so. I created a file that was 256 long and saved it to my c:\ no problem. Then I tried to create that same file pointing it to \\phaedrus\data\ and it did not work. This share is to the root of the D drive on the server to the overall path should work. When I try reducing the file name I find it finally works at 244. I was thinking it was counting the UNC \\machine\share but that's 17 characters and this is off by 14.

Link to comment
Share on other sites

I have figured most of it out but I still have a couple of questions.

 

I finally realized there are two primary things that limit path\file size. The file system, in this case NTFS, and the Windows API. The Windows API limit's the maximum path and file string to 260 characters. Presumably they came to this back when older operating systems could only have a total path+file length of 2^8=256 plus the 3 characters for the drive EG "c:\" and a null character. NTFS has a limit of 256 for any file name or directory name so it isn't so much like set total limit but I do believe there is one out there at some 32k+ characters. I wrote a macro that loops thru and creates increasingly larger strings for names and tries to create a file until the limit is reached and it bears out for the most part.

 

One thing to beware of is files created in the root. You see one might like to just use the 260 limit but there is at least one place this will get you in trouble and that's the root of a drive. In the root of a drive the limit is 259. I believe this is because of the NTFS 256 char file limit kicking in. 256 plus the 3 chars of "c:\" kills it. Can anyone else out there confirm this for me?

 

Next question is regarding a potential pitfall with this arrangement. The pitfall is that over the network one can create a shorter path than is on disk. EG you could have a local path on the server of c:\some\really\long\path\name\ but share that folder as \\server\data\. So when you're visiting via the share it all works swimmingly. But if you were to try and access that file from the server it will complain that it can't because the name and path are too long. This can actually work the other way as well. Does anyone know of any way to test for and avoid this? I know I could use my knowledge of specific shares and paths to do this but I was looking for a way to incorporate it into a generic sub-macro.

 

I wanted to create a test for file names and this is my rough draft and I would like to see if anyone can find fault with it.

 


  1.  

  1. Test that <drive><path><name><ext> not exceed 260
  2. Test that <name>ext> not exceed 256
  3. Test that any portion of the path between the backslashes not exceed 256 (might be practically unnecessary)
  4. Test that the local path not exceed 260 (if at all possible)
  5. Test that there are no invalid characters

 

Can anyone find fault with this? Can anyone think of any more things to add?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...