?
Solved

Limit Windows path and file name length.

Posted on 2007-08-08
8
Medium Priority
?
12,217 Views
Last Modified: 2011-12-15
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.
0
Comment
Question by:mrsmileyns
8 Comments
 
LVL 30

Expert Comment

by:LauraEHunterMVP
ID: 19656866
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.  :-(
0
 
LVL 4

Accepted Solution

by:
funnyfingers earned 1000 total points
ID: 19657568
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.
0
 
LVL 10

Expert Comment

by:Walter Padrón
ID: 19657726
Just a shoot in the dark ;)

Any path can be converted to 8.3 format which is in fact shorter than this limit.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 86

Assisted Solution

by:jkr
jkr earned 1000 total points
ID: 19663178
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".
0
 

Author Comment

by:mrsmileyns
ID: 19682920
jkr...where do I specifiy those settings?  In enviromnet variables?  I am not entirely sure what you are refering to.
0
 
LVL 86

Expert Comment

by:jkr
ID: 19684481
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.
0
 

Author Comment

by:mrsmileyns
ID: 19685003
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.  
0
 

Expert Comment

by:HRSBTech
ID: 22528943
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 
	path21=left(path2,path20)
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
Next
 
For Each i In oDir.SubFolders
DoStuff i.Path
Next
End Sub
WshShell.Run "notepad.exe longpath.txt"

Open in new window

0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Screencast - Getting to Know the Pipeline

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question