File Naming policy restrictions on Windows Server - 2012 R2 File Server long paths issues

We have 2012 R2 Windows servers , but most of our users are Mac users. We have a number of shares on the Windows fileserver. Users are creating new files with very long name . We also have very deep folder paths which create a lot of issues. Is there anything I can do on the Windows file server to not allow the users create long  folder names or long file names? Thank you,
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rodney BarnhardtServer AdministratorCommented:
I do not believe there is a way to do this at least natively in Windows 2012. I have the same problem and we are almost entirely a Windows shop. It is particularly a problem when a user has a long file name and dumps it in a deep folder.

In fact, this link discusses how it is still a problem with no real work around other than some from of document management system.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lionel MMSmall Business IT ConsultantCommented:
There is no way to restrict this that I am aware of. Only thing you could do is run a script every night, create a log file with all the files names that are too long (you decide what the length is) and then you can inform these people that these filenames are too long and they need to change it. You could automate it to have the script email the users directly if you prefer that approach.
netcompAuthor Commented:
The file server has about 12 TB of data. I wonder how lung would the script take to check the file-names or paths.  Where can I get such script . Also, how could you tell who was the last user that modified it . Is there anything in 2012 that can keep track of who made what change. I know of the old fashion way enabling auditing on the drive, but who wants to do go through gazillion of security logs in EV. Thank you,
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Lionel MMSmall Business IT ConsultantCommented:
I would approach it like this--first find the ones that do not meet the required naming conventions (those that are too long) and put those into a txt file, then parse that text file and get the creator's name (I would assume you want the name of the one who created it and not the one who last used it, no?). This is how I would check for length of file name
you can use vbscript
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\FolderName"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
      WScript.Echo strFile.Name,Len(strFile.Name)

save the above as myscript.vbs and on command prompt
c:\Utils> cscript /nologo myscript.vbs

I will get you the rest of the script later today
Lionel MMSmall Business IT ConsultantCommented:
I am having a very busy Monday so I did a quick look to see if others have already come up with a solution to this issue and I found this one for you--please test it out and let me know if it creates a list of file and path names lengths--I should have more time later in the week to help you more on this
Bill PrewIT / Software Engineering ConsultantCommented:
Unfortunately I know this would probably be too slow across a 12TB drive, but this DOS solution will indeed find the long path names.  Most other script solutions like VBS or PS will not, they will error when they hit files too long.  Perhaps you want to try it as a test on a small area where you know there are bad files just to confirm the results.  But not sure it is your ultimate solution, unless you can run it overnight for hours if needed.

@echo off
setlocal EnableDelayedExpansion

rem Define folder to scan, and length to report files with a longer path
set BaseDir=C:\Users\Username\AppData\Local\Packages
set MaxLen=250

rem loop through all files
for /f "tokens=*" %%A in ('dir /a-d /s /b "%BaseDir%"') do (
  rem Calculate length of full path
  call :StrLen "%%~A" Len
  rem If exceeds threshold report on it
  if !Len! GEQ %MaxLen% (
    echo %%~A

rem Exit main script
exit /b

rem Subroutine to get the length of a string passed as a parm, and return length in variable name passed as a parm
:StrLen [string] [len-var]
  set "_str=A%~1" & set "_len=0"
  for /L %%A in (12,-1,0) do (set /a "_len|=1<<%%A" & for %%B in (!_len!) do if "!_str:~%%B,1!"=="" set /a "_len&=~1<<%%A")
  set /a %~2=%_len%
  exit /b

Open in new window

[ EDIT: Added missing "(" on this line:   if !Len! GEQ %MaxLen% ( ]
oxishmit oxishmitCommented:
i suggest you to try Long Path Tool.
Bill PrewIT / Software Engineering ConsultantCommented:
I have no personal experience, but watch out for Long Path Tool, seem to be some sketchy reports against that site.

netcompAuthor Commented:
Thanks all- I ended up using Acronis Access connect to limit file size, but still have some issues.
Thanks for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2012

From novice to tech pro — start learning today.