# Max\_path\_length limitation

**URL:** <https://swi-prolog.discourse.group/t/max-path-length-limitation/5304>\
**Category:** Help!\
**Tags:** discussion\
**Created:** [April 19, 2022, 12:56pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304 "2022-04-19T12:56:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![duesentrieb17](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/duesentrieb17/32/4333_2.png) [@duesentrieb17](https://swi-prolog.discourse.group/u/duesentrieb17)\
**Post date:** [April 19, 2022, 12:56pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/1 "2022-04-19T12:56:33Z")

</div>

I’m using: SWI-Prolog version 8.4.2

There is a real show stopper in our application with v8.4.2.  
Specifically, it is this artificial limitation of the path length of around 259:

```prolog
?- absolute_file_name('1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',A).
ERROR: Cannot represent due to `max_path_length'
ERROR: In:
ERROR: [11] '$absolute_file_name'('1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',_4810)
ERROR: [9] toplevel_call(user:user: ...) at c:/programs/swi-prolog_8.4.2/boot/toplevel.pl:1158
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 19, 2022, 1:27pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/2 "2022-04-19T13:27:24Z")

</div>

According to Microsoft the PATH\_MAX limit is 260 ☹ As I understand it, this may be disabled in Windows 10 through the registry. Is it disabled by default in Windows 11? When disabled the max seems to be 32K with an additional max for each component (how high?).

There are probably fairly easy quick work-arounds, i.e., by overruling PATH\_MAX while a more principled fix will require some real work. If this is commercial work, please contact me using a personal message.

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [April 19, 2022, 1:36pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/3 "2022-04-19T13:36:21Z")

</div>

> [@jan](#):
>
> Is it disabled by default in Windows 11?

I get same result using Windows 11 with SWI-Prolog 8.5.5.

* * *

I can’t remember the exact details but one should be able to use a Windows symbolic link ([guide](https://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/)) for the part of the path that does not change then hopefully the reminder of the path is less than the 260 character limit.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 19, 2022, 1:55pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/4 "2022-04-19T13:55:55Z")

</div>

The C header files define PATH\_MAX as 260. This doesn’t seem to (always) apply to Windows itself. SWI-Prolog however uses PATH\_MAX. If we redefine that we may hit limits further down the pipeline. For some of this, these are the MSVC somewhat POSIX compliant runtime functions. Other parts of the file system API call the Windows native Win32 API.

Raising it a bit should be harmless. Raising the limit to 32K requires some care at several places as some of the functions processing paths allocate several PATH\_MAX arrays of wide characters on the C stack while the Windows stacks are by default rather small.

---

<div class="post-metadata">

**Author:** ![duesentrieb17](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/duesentrieb17/32/4333_2.png) [@duesentrieb17](https://swi-prolog.discourse.group/u/duesentrieb17)\
**Post date:** [April 19, 2022, 2:34pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/5 "2022-04-19T14:34:11Z")

</div>

Good old SWI-Prolog v5.9.7 does not have the problem (on the same machine):

```prolog
1 ?- absolute_file_name('1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111',A).
A = 'c:/programs/swi-prolog/bin/1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'.

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 19, 2022, 2:51pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/6 "2022-04-19T14:51:03Z")

</div>

> [@duesentrieb17](#):
>
> v5.9.7 does not have the problem

That is really good old 🙂 Most likely it failed to pick up `PATH_MAX` from the headers and arbitrarily defined it (1024?). @mgondan1 fixed some of that 🙂

Most probably we can restore the old behavior. That is not a proper fix, but might be good enough for 99% of the users.

---

<div class="post-metadata">

**Author:** ![duesentrieb17](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/duesentrieb17/32/4333_2.png) [@duesentrieb17](https://swi-prolog.discourse.group/u/duesentrieb17)\
**Post date:** [April 21, 2022, 8:29am UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/7 "2022-04-21T08:29:25Z")

</div>

Yes please restore the old behavior.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [April 21, 2022, 4:27pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/8 "2022-04-21T16:27:44Z")

</div>

Might work with the latest binaries in the daily download section. Not tested.

---

<div class="post-metadata">

**Author:** ![remy.s](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@remy.s](https://swi-prolog.discourse.group/u/remy.s)\
**Post date:** [January 29, 2023, 11:19am UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/9 "2023-01-29T11:19:13Z")

</div>

With

```prolog
Welcome to SWI-Prolog (threaded, 64 bits, version 9.1.4-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

```

on a Mac (m2), I get the same error!  
Has anyone found a workaround for this?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [January 29, 2023, 5:25pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/10 "2023-01-29T17:25:49Z")

</div>

Windows and the rest pretty much have distinct code for handling this stuff. Most systems I’m aware of do have a limit on the path length (`PATH_MAX`). If somehow that is not correctly picked up the system assumes 1024. So, what call exactly are you making?

---

<div class="post-metadata">

**Author:** ![remy.s](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@remy.s](https://swi-prolog.discourse.group/u/remy.s)\
**Post date:** [February 12, 2023, 1:42pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/11 "2023-02-12T13:42:58Z")

</div>

Sorry for my late response.  
Actually, I was using exists\_file/1.  
But after more careful checking, I found that I was using a recursive clause which created ever longer paths, and then at some point hit this limit.  
After verification of my system’s files, I would conclude, that from a practical point of view, the Max\_path\_length limit is a non issue.  
Sorry for bothering you with this.

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [February 19, 2026, 9:06pm UTC](https://swi-prolog.discourse.group/t/max-path-length-limitation/5304/12 "2026-02-19T21:06:42Z")

</div>

See:

> **[Maximum Path Length Limitation - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry)**
>
> Starting in Windows 10, version 1607, MAX\_PATH limitations have been removed from many common Win32 file and directory functions. However, your app must opt-in to support the new behavior.

For solution using Windows registry see later in the page

> **[Enable long paths in Windows 10, version 1607, and later - Maximum Path Length...](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later)**
>
> In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX\_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name...

I was able to fix a SWI-Prolog path exceeded limit error by just changing the registry value. Did not need the part about Application manifest, YMMV.
