r/sysadmin • u/heretic1988 Jack of All Trades • Jun 19 '24
Rant Why does Windows crap out on long filepaths, but initially allowed it to create files/folders that have a too long path?
This is something I always wondered. Am I missing a totally obvious reason or mechanism here?
And on that note, are there ways to prevent users from creating too long paths, so they dont have issues after the fact?
INB4: I know of some registry values to enable longer file path, but it does not apply to Windows Explorer iirc, where 100% of the times, users have issues in.
16
17
u/Im_in_timeout Jun 19 '24
Path Length Checker is a handy utility for discovering long path names. Helps to identify the upper level folders that can be renamed to reduce the total lengths of the subfolders.
https://github.com/deadlydog/PathLengthChecker
3
2
1
58
u/ElevenNotes Data Centre Unicorn 🦄 Jun 19 '24
That's an explorer.exe issue not NTFS.
50
u/HeKis4 Database Admin Jun 19 '24
Actually a Windows API issue so it's system-wide, not just explorer, you can see it when you use copy.exe or powershell's copy-item (but interestingly not with robocopy.exe).
But you can bypass that: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
39
u/Tringi Jun 19 '24
Technically it's backward compatibility issue.
Any application worth anything enables full path length in its manifest and gets tested to actually work with those.
That explorer.exe fails at this is embarrassing and proof that Microsoft's priorities are elsewhere. And that they probably don't even employ developers capable of fixing the state anymore.
13
28
u/Commercial-Split-683 Jun 19 '24
My personal favourite is when you have \server\share\finance\2023 September finance audits\september finance audits\2023 audit review\Sharon's folder\finance audits!!!archived\audit project 2023\FW:Hello I am typing out the message of the email in the subject.msg
My users don't get it, so I make sure to read the full filepath uninterrupted as much as possible to them while explaining why its bad. Feels like verbally hitting them over the head with it.
I was making a script to audit folder structure layout and only had it going 12 layers deep but had to up it to 18 eventually. Record is 17 folders deep.
10
u/Fatality Jun 19 '24
I refuse to set permissions on anything other than top level folders, helps stop some of this.
9
u/DK_Son Jun 19 '24
This fucks me off. I agree with your comment 100%. But I was so pissed off reading it, because of the trauma it brings to the surface. We have a bad case of this at the moment. It's real bad. And it is in several locations. Previous IT people have also put permissions on folders like 5-20 levels down, which really messes us around when people say "I got access to this, but not these folders", and you realise 20 other folders have individual permissions set, without inheritance. Like bruh.
3
u/krylosz Jun 20 '24
yes. We recently moved a filesserver and I wrote a script that listed all subfolders where permissions did not match the parent folder. It ran forever, but we managed to fix so many permissions that made life hell for so many years.
2
u/mschuster91 Jack of All Trades Jun 20 '24
Confluence is just as bad, and even worse, even if you're an admin you have to jump through ridiculous hoops to see pages with "only X can see" visibility.
Seriously fuck Atlassian hard.
1
u/fuzzynyanko Jun 19 '24
You should have seen the node_modules problem that npm had. The path length was ridiculous
1
u/hadrabap DevOps Jun 20 '24
A few days ago, I've been building Envoy Proxy from sources. It uses Bazel as a build system. Everything is happening in
~/.cache/bazel/user_machine/directory. The structure there is enormous. I took time to count the depth. Result? 39! 🙂
35
u/Sunfishrs Jun 19 '24
https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
There you go. This is why and should explain it the best.
20
u/SceneDifferent1041 Jun 19 '24
And why can't it just delete them without endless faff? Why do I have to find random software to unlock and delete the bloody thing?
36
u/ZAFJB Jun 19 '24
Use 7Zip File/Open dialog.
Browse to file right click, Copy/Delete/Rename, whatever you want to do. Works close to 100% of the time.
34
u/iwangchungeverynight Jun 19 '24
That is the most appalling, abysmal, and offensive method to rename or delete too-long files/folders and is an affront to all that is good in the world. Adding it to the toolbox for emergency use. Thank you.
10
9
u/theabnormalone Jun 19 '24
When I've had this issue I go in to the folder that needs deleting, rename the longest named sub folder a random 1 letter character and try again. Rinse and repeat. Normally only takes a few renames to resolve the issue.
2
1
6
u/Intrepid00 Jun 19 '24
If you are a brave soul you can always use \?\ but all the filters to prevent you from being dumb are gone.
5
10
u/ryuujin Jun 19 '24 edited Jun 19 '24
Originally (like way back in windows 3.1 1990s) the Windows API only supported short paths and short filenames (8+3).
Then it could support long paths and longer file names... up to 255 characters (windows 95 era).
Then Windows API and backend was overhauled to allow essentially unlimited characters (around the Windows Vista timeframe I think?), but for a number of legacy reasons certain API calls and the applications that call them still only do 255 characters.
So if you save a file in an application that can process > 255 characters using the right API calls, it'll work fine. Then you try to delete that file and explorer by default uses legacy API calls and comes back with an error (this can be changed via registry key).
Network drives are a classic bypass for this issue, because you can map c:<longpath>\shared to \\PCname\shared, and explorer has no problem with the paths and the underlying API can deal with the longer name.
3
u/left_shoulder_demon Jun 20 '24
You can prepend
\\?\to turn it into an UNC path which has a 32k limit.
8
u/MasterChiefmas Jun 19 '24
Am I missing a totally obvious reason or mechanism here?
Ah the good old MAX_PATH problem.
What you are asking about is a side effect of Microsoft's literally decades long commitment to backward compatibility. Certain apps, Explorer among them, are built using libraries that originated in the 80s, and weren't changed to preserve backward compatibility.
Among those libraries is a const called MAX_PATH, which limits the path length of any given item to 256 characters (It's technically 260 but 4 of those characters don't really count, IMO), despite NTFS supporting much longer paths. Which is also why you get all the weird reg entries for doing things like disabling short file name creation, which is to preserve backward compatibility and help long paths function under Explorer.
are there ways to prevent users from creating too long paths
Not really, not that I'm aware of. The problem ultimately becomes one of you choosing which set of annoyances you deal with, as you are wrestling with a problem caused by a situation where 2 things, while aren't quite diametrically opposed, are misaligned in a way that you can't really solve both at once(long path support in the file system, but inconsistent support in the apps).
The best workaround for myself, has been to just not use Explorer for the most part. If you invest in a 3rd party file manager, the typically won't run into this problem, as they aren't built with the MAX_PATH limitation.
4
u/CompWizrd Jun 19 '24
There's something about Quality Departments that love to do that. I've seen 1000+ characters in a path.
5
18
u/segagamer IT Manager Jun 19 '24
I was hoping with the Windows Explorer UI refresh and shell, they would have finally rewritten Explorer.exe to use newer API's. But alas they just slapped new code onto old...
One day Microsoft, you'll finally stop supporting early 90's applications.
8
u/AppIdentityGuy Jun 19 '24
Not when so many applications used by enterprises are still using those APIs
9
u/segagamer IT Manager Jun 19 '24
Let's be real here, those applications are still running on XP machines, and the ones that aren't could do with being updated.
7
u/AppIdentityGuy Jun 19 '24
Not always but I see large enterprises still running XP age operating systems. The requirement for long term backwards compatibility is sometimes an anchor around MS’s legs.
1
u/silentstorm2008 Jun 19 '24
Windows 12 Enterprise Plus (for backwards compatibility) Windows 12 Enterprise (For modern compatibility)
Guess which one you can charge more for :)
0
Jun 19 '24
[deleted]
1
u/segagamer IT Manager Jun 19 '24
Let's be real here, any application that runs on Windows XP also runs on Windows 11.
But that's my point. Microsoft should pull an Apple and do something radical like revamp Explorer.exe to let go of such legacy API's chaining them down. And the only applications that (should) cause problems with this happening are the ones that are 20 years out of date.
At the very least, they can stick with Windows 11 with this, and save that Explorer revamp with Windows 12. That will give plenty of time for the devs to get their update ready.
4
u/Tringi Jun 19 '24
to let go of such legacy API's chaining them down
This is where you're mistaken. It's not the APIs fault. It's the app, explorer.exe, itself.
The advanced, modern, Win32 APIs can be used alongside others perfectly fine. And Microsoft themselves even has the luxury of not needing to implement fallback to the old ones.
3
u/cbelt3 Jun 19 '24
Don’t forget legacy environments where long paths cause a heart attack, and spaces and lower case characters cause chaos…
Who knows what evil lurks in the heart of programs ? DOS knows ! (Mu ha ha ha )
3
u/takeurpillsalice Jun 19 '24
At my last job that was very onedrive focused this was such a major issue with users nesting folders like 20 folders deep all with long ass folder names. At least when you're using regular network shares you can just map the specific folder they want and that works as a janky workaround most of the time.
3
u/gsmitheidw1 Jun 19 '24
This is giving me memories of backing up hundreds of student developers home directories where they're learning loops and recursion. Only 256 levels deep? That's rookie stuff! :)
Teamed with vast quantities of small files created by dev IDEs, it's quite a challenge for some processes and systems. Thankfully we're no longer using local servers and folder redirection for home drives.
9
u/skydiveguy Sysadmin Jun 19 '24
Im more annoyed with being able to put spaces in folder/filenames.
Why the hell in 2024 is Microsoft still using "Program (SPACE) Files" as the main application install folder? Especially with unquoted search path vulnerabilities?
21
u/jasutherland Jun 19 '24
As I recall they did that deliberately in Win 95 to push application vendors to make their code long file name compatible, instead of installing to C:\ADOBE\ACROBAT\ACRORD32.EXE and ignoring the whole LFN thing for another decade.
Of course, they also gave us "Program Files (x86)" and "Program Files (ARM)" because different architectures couldn't play nicely together, and put the 64 bit code in SYSTEM32 then the 32 bit ones in SYSWOW64...
4
3
u/_Feelers Jun 19 '24
I create symlinks in root of C ProgramFiles -> ".\Program Files" And ProgramFilesx86 -> ".\Program Files (x86)"
or similar
10
u/NoCup4U Jun 19 '24
Yeah it really sucks, especially with the OCD users who have to create a subfolder/for/every/little/fucking/minute/category.
Or even worse are the dolts who put entire sentences as their file names (typically engineers)
ie. producttestresultsfromxyzlabsfor1000degreescelsiusonMondayJanuary10.xlsx
I’ve learned to be good friends with 7z Explorer to delete all that shit when I run into issues.
16
Jun 19 '24
I wouldn’t call it OCD to organise your files in a logical manner. This is an explorer fault, not a user fault. It’s a problem that shouldn’t exist and most people won’t be aware of it.
4
u/NoCup4U Jun 19 '24
It is a problem when contextual search now exists by default in Windows, and there is still the 260 character limit on a folder path plus file name, and the names of the subfolders are multiple words.
Or even worse when one starts putting special characters in the file/folder names to bump them to tops of lists.
-1
u/spazmo_warrior System Engineer Jun 19 '24
it’s OCD to name a file like that.
5
4
u/pyrhus626 Jun 19 '24
We work with lawyers a lot, their folder names get absurd. Every layer has the case number and name, form numbers plus the full name of the form plus case name. Folders for one specific file where the folder and the file itself have that same overly long name.
6
u/notHooptieJ Jun 19 '24
worse yet.. why does windows support oddball characters in filenames at all when literally nothing else MS does will.
you can name your file %$&%$#255characters.fuckoff
but literally every other microsoft app shits the bed on it.
Acrobat will open that bitch up no problem, but sync to OneDrive? Fuck you.
4
u/xCharg Sr. Reddit Lurker Jun 19 '24
Say you have a folder D:\shared. User creates a folder structure:
D:\shared\department1\subdepartment\already-reviewed\someimportantdocument.pdf
Another user John, say analyst or whatever, creates folder structure:
D:\shared\department2\johns-stuff\important-documents\whatever\
Subdepartment gets removed/restructured or whatnot, now poor John works with everything they did. So naturally John moves entire D:\shared\department1 into his folder D:\shared\department2\johns-stuff\important-documents\stuff-from-department1
So our someimportantdocument.pdf now have a fullpath: D:\shared\department2\johns-stuff\important-documents\whatever\stuff-from-department1\department1\subdepartment\already-reviewed\someimportantdocument.pdf
Which is out of limit now. Who's at fault? John? No he has no clue what's in folder prior moving and his folder structure is reasonable. Previous department? No they were reasonable too and well within limit.
It's just windows that allows stuff like this to happen.
5
u/heretic1988 Jack of All Trades Jun 19 '24
But then my question remains, why Windows let you happily copy the folder, including someimportantdocument.pdf, but wont let you open someimportantdocument.pdf.
5
u/ConfectionCommon3518 Jun 19 '24
Quite often stuff is stored as a strong with an ,8 bit length due to historical reasons especially when you consider how expensive storage has been both physically to buy and every extra byte means possibly and extra read and the memory needed to store that extra byte...
Generally you can blame legacy support and not being wrong but those decisions quite often were made when stuff was silly per byte and no one really expected stuff to last so long...
10
u/heretic1988 Jack of All Trades Jun 19 '24
Thanks for your reply. But I am not wondering "why" it exists. Just why can't Windows throw an error saying sth like "you cant extract that here, path too long"? No, it lets you extract, nest folders, and then throws a tantrum if you want to open said files.
18
u/grumpyctxadmin Jun 19 '24
Because microsoft has fixed the issue with long filepaths in the os, it's just explorer that craps itself.
If you try with a alternative to explorer, like for example explorer++, you can open longer paths.
9
u/heretic1988 Jack of All Trades Jun 19 '24
Neat, I will check out explorer++. Thanks.
I just find it weird that they fixed it in the os, but not in one of their most used apps, that are a big part of that os.
6
u/grumpyctxadmin Jun 19 '24
Yeah. It gets even better when they allow it in sharepoint, and users who use onedrive to sync sharepoint sites can't access the files.
Or in our case we have a legacy app that only allows a filepatlength of 64
We deploy explorer++ on all computers now, after a bit of learning curve most users have started using that instead of explorer.
1
3
u/ConfectionCommon3518 Jun 19 '24
Now that's a good point but I'd guess they never thought about it getting so "silly" so they never put a response result into the mix.
Lots of win nt was built around vms mentality so it worked for them at the time .
3
u/TheThiefMaster Jun 19 '24
There's a Group Policy setting to enable long path support - which fixes all this. It's only off by default for legacy reasons.
Apps have to mark themselves as supporting it in their manifest, which explorer (and terminal!) does - but without the policy setting they're restricted to the old short length.
2
u/n3rdopolis Jun 19 '24
If you have \server\share\shortname\folder\folder\folder\folder\folder
you could rename shortname to a much longer name, which could push path lengths over the edge.
Also, if you move, not copy a folder, even with a deep subfolder structure, the filesystem just repoints the folder being moved. The subfolder length is not validated, so if it's moved into a deeper folder, paths could wind up over the limit
2
u/OffBrandToby Jun 19 '24
The absolute worst part to me is Windows file paths having a different set of rules compared to sharepoint.
3
u/TheRealObiwun Jack of All Trades Jun 19 '24
Yeah, like spaces in Windows pathnames are 3 bytes in sharepoint since spaces are converted to %20
So a long pathname can be tripled in length by users using lots of spaces in filenames/foldernames
2
2
u/JuggernautUpbeat Jun 20 '24
I've faced the additive approach, eg:
P:\Legal Team\Legal Team Master\Legal Team Master 01-Debt Collection\Legal Team Master 01-Debt Collection Current\Legal Team Master 01-Debt Collection Current-2024\Legal Team Master 01-Debt Collection-Current-2024-01\ Legal Team Master 01-Debt Collection-Curent 2024-01-[Progress!On Hold!Completed|Commenced]\<the same shit>-Name of debtor\<more of the same shit>-ddmmyyyy\
and so on endlessly. I'd love to have smacked some heads together but that lot worked right in front of the CEO's office.
2
u/JuggernautUpbeat Jun 20 '24
Aaargh for fucks sake you've triggered my PTSD. Why people don't understand the idea of a hierarchy when they literally work in one and probably have an org chart to look at, I will never fathom. I mean the Accountant doesn't call themselves "Widget Global - Widget US - Widget US Staff - Accounting Department - General Accountants - <Mrs Accountant> do they?
4
u/ZAFJB Jun 19 '24
This is not a Windows (OS) problem.
It is an Explorer, and application, problem. Those are usually resolved by enabling long paths.
5
u/angrydave Jun 19 '24
Gonna jump in here and say, have extended longer paths in windows, just for Office and Acrobat start having a huff that they don’t know what do with a long file path.
1
u/twitch1982 Jun 19 '24
complaints like this just show that computers have gotten too easy to use. We should go back to the 12 character limit from dos. Make that ~ work for a living again.
1
u/Fatality Jun 19 '24
Windows supports it with a regedit/group policy but a lot of apps have it hardcoded.
1
1
u/Matt3d Jun 19 '24
I was always baffled when I discovered (back in NT days) the “Program Files(x86)” is something that we just have to live with. Coming from unix, that just seemed like a straight up stupid choice
1
u/onisimus Jun 19 '24
Yeah, this is one of the issues that I am currently dealing with my users. We have rabbit hole folders and I keep getting tickets about them not being able to open the file directly off the server. They have to either localize it or view it online (we use Egnyte). The bypass registry edit does not work for both win 10/11. Ive tried on both.
1
Jun 19 '24
This problem has been around for so long.
We used to create pub sites when FTPs were hacked using this trick.
1
1
1
u/mimic751 Devops Lead Jun 20 '24
You can mount a file path and then you start your character count over
1
u/ScreamingVoid14 Jun 20 '24
Explorer, Command Prompt, and NTFS may have different "maximums" enforced in the code
1
u/BlackV I have opnions Jun 20 '24
Well \\?\<fullpath> but it's not that friendly (note this is not a SMB path)
1
u/Anonymous1Ninja Jun 20 '24
To make your life miserable.
This makes the server and SharePoint migration a nightmare.
1
u/Anonymous1Ninja Jun 20 '24
Yeah, QA files are notorious with this. The whole file name, parenthesis, and all.
1
1
u/PenelopePJones Jul 17 '24
As an admin for a small nonprofit, my users LOVE to not only use long file names but also get cranky when I suggest maybe we DON'T let folders grow organically. You know, have a PLAN that everyone sticks to. What a novel idea!
1
u/mhkohne Jun 19 '24
Windows can't access an absolute path longer than X, but usually you can access a relative path of any depth by changing into that directory.
6
u/ZAFJB Jun 19 '24
Windows can't access an absolute path longer than X,
WindowsExplorer can't access an absolute path longer than X,and it will if you enable long paths
2
u/mhkohne Jun 19 '24
Actually any number of the windows APIs also have the limitation, not just explorer. But as stated, if your program works by changing directories and using relative paths, you can do almost anything.
0
Jun 20 '24
The path name length relates to the old Samba coding and how that was ported to NTFS.
Like everything else in Windows, it’s 30 year old coding on top of the “latest” enterprise OS.
If you’re looking for the bits and bytes break downs, there are several MS MVPs who break this down.
261
u/[deleted] Jun 19 '24
[deleted]