Limit Windows path and file name length.

Is there a utility or policy that can limit users from creating a path and filename combination that exceeds a specific threshold i.e 255 chars or whatever I specify?  I am having some issues with my users creating paths and file names that are 280 + chars.  This invariably leads to problems.  Is there a way we can stop them from doing this through a policy of some sort...either native MS or third party?  We are running a 2003 shop with XP clients.  Thanks.
Who is Participating?
The limit on a filename is 255 and the limit of path+filename is 260.  If you are seeing 280 in length this means your share path name (\\Server01\Username) is smaller than the path where the files are actually store on the server (D:\Data\Users\Username\).  This problem should also make it so you couldn't open up the long length directly from the server and you would have to open it from a share.  You can increase the share length which would force them to choose shorter filenames, though if you did that without prior notification they may not be able to open files that are too long.

Another problem would come where you can increase the length of folder name containing the long filename and then you would not be able to open that file.

I am pretty sure that you cannot limit this so I would just suggest that you increase the share length in case your files can not be backed up since they went of the 260 character limit because of a possibly short share path.

As for a 3rd party utility the only thing I can think of would be something to scan your data every night and report on long file names but I don't think that is what you really want.
I am unaware of third-party tools that will accomplish this (maybe someone else will pipe in), but I know that it can't be done natively within Windows.  This is a common request, but at the moment "user education" is your only refuge.  :-(
Walter PadrónCommented:
Just a shoot in the dark ;)

Any path can be converted to 8.3 format which is in fact shorter than this limit.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

You can use paths longer than MAX_PATH characters by cprepending "\\?\" to the path. The "\\?\" tells Windows to turn off path parsing. This lets you use paths that are nearly 32,000 Unicode characters long. However, each component in the path cannot be more than MAX_PATH characters long. You must use fully-qualified paths with this technique. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\tom_1\hotstuff\coolapps" is seen as "\\tom_1\hotstuff\coolapps".
mrsmileynsAuthor Commented:
jkr...where do I specifiy those settings?  In enviromnet variables?  I am not entirely sure what you are refering to.
This is not a setting. You wrote "I am having some issues with my users creating paths and file names that are 280 + chars" - using the above naming conventions, you can easily deal with those paths.
mrsmileynsAuthor Commented:
I see - now that I reread your comment it makes more sense - if users put the \\?\ at the start of the path it will work beyond 255 or 260 chars as long as each "section" of the path is not beyond MAX PATH.  I think I understand.  It is not entirely what I am looking to do but it is VERY good to know and something I was not aware of.  Thank you.  
I am backing up my windows 2003 user folder on an XP backup server.  If a user has a file path longer than 255 char, the backup will hang.

I wrote this simple vbs to scan my user directory on the 2003 server.
I works well for me.

'*                                author Bertrand Vogel                                            *
'* this script will create a log (longpath.txt) of the paths exceeding  250 characters             *
Dim objFSO, objFileCopy, strPath, strfilepath, objFolder, strDirectory, filesys
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
set filesys=CreateObject("Scripting.FileSystemObject")
'strpath could be hard coded here (ie: strpath = "d:\users") in stead of opening the input box.
strPath = InputBox("Enter Folder Path you want to scan (ie d:\users): ")
Set fOut = oFSO.CreateTextFile("longpath.txt", True)
DoStuff oFSO.GetFolder(strPath).Path
Sub DoStuff(sDir)
'********** set path lenght here ***********
if len(sdir) > 250 then
	fOut.WriteLine sDir
end if
Set oDir = oFSO.GetFolder(sDir)
For Each i In oDir.Files
path11=instr(sdir, "\") + 1
path2= mid(sdir,path11)
path20=instr(path2, "\")-1
if path20 > 0 then 
end if
'********** set path lenght here ***********
if len(sdir & "\" & i.Name) > 250 then
	fOut.WriteLine ""
	fOut.WriteLine "length of the following path is " & len(sdir & "\" & i.Name)
	fOut.WriteLine sdir & "\" & i.Name
end if
For Each i In oDir.SubFolders
DoStuff i.Path
End Sub
WshShell.Run "notepad.exe longpath.txt"

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.