Re: Error: file name for OPEN is too long

new topic     » topic index » view thread      » older message » newer message

Matt Lewis wrote:

> Juergen Luethje wrote:
> > 
> > Hello all,
> > 
> > using exw.exe 3.1.1 on Windows XP, a program crashed with the error message:
> >    file name for open() is too long 
> > 
> > According to my tests, complete file names (including path and extension)
> > up to a length of 254 characters are working fine. With names longer than
> > 254 characters I get this error. Can someone confirm this?
> > 
> > What are the maximum possible lengths of complete file names on modern
> > Windows systems, and on Linux/FreeBSD? Is it possible to change the Eu
> > interpreters/translators, so that file names with the maximum length on
> > the concerning OS can be used with Eu programs?
> 
> As Derek mentioned, these are Windows limitations (but the interpreter 
> also limits the length--probably because of this).  Below is some info
> from msdn (copied/pasted, because who knows how long it will be before
> MS reorganizes).  I think you could probably get around this by changing
> the current directory (possibly several times) and using relative paths.

This is an interesting idea, thanks.

> The alternative is to possibly use unicode, which would be a lot more work,
> 
> and would require significant changes to the interpreter.
> 
> <a
> href="http://msdn2.microsoft.com/en-us/library/aa365247.aspx">http://msdn2.microsoft.com/en-us/library/aa365247.aspx</a>
> Naming a File
> 
> Maximum Path Length
> 
> In the Windows API, the maximum length for a path is MAX_PATH, which is 
> defined as 260 characters. A path is structured in the following order: 
> drive letter, colon, backslash, components separated by backslashes, 
> and a null-terminating character, for example, the maximum path on the 
> D drive is "D:\<256 chars>NUL".
> 
>     Note  Functions in the Windows API convert "/" to "\" as part of
>     converting the name to an NT style name.
> 
> The Unicode versions of several functions permit a maximum path length of 
> approximately 32,000 characters composed of components up to 255 characters
> in length. To specify that kind of path, use the "\\?\" prefix.
> 
>     Note  The maximum path of 32,000 characters is approximate, because 
>     the "\\?\" prefix can be expanded to a longer string, and the expansion
> 
>     applies to the total length.
> 
> For example, "\\?\D:\<path>". To specify such a UNC path, use the 
> "\\?\UNC\" prefix. For example, "\\?\UNC\<server>\<share>". These prefixes
> 
> are not used as part of the path itself. They indicate that the path 
> should be passed to the system with minimal modification, which means that 
> you cannot use forward slashes to represent path separators, or a period to
> represent the current directory. Also, you cannot use the "\\?\" prefix with
> a relative path. Relative paths are limited to MAX_PATH characters.
> 
> When using the API to create a directory, the specified path cannot be so 
> long that you cannot not append an 8.3 file name.
> 
> The shell and the file system have different requirements. It is possible 
> to create a path with the API that the shell UI cannot handle.
> 
> Relative Paths
> 
> For functions that manipulate files, the file names can be relative to the 
> current directory. A file name is relative to the current directory if it 
> does not begin with one of the following:
> 
>     * A disk designator, which is either a drive letter followed by a colon,
>       or a server name and share name (\\servername\sharename).
>     * A directory name separator, such as a backslash, for example, \subdir).
> 
> If the file name begins with a disk designator and a backslash (\), it is 
> a full path (for example, c:\tmp). If a file name begins with only a disk 
> designator, it is a relative path to the current directory on the drive 
> with the specified letter (for example, c:tmp.txt refers to a file in 
> the current directory on the C drive).

Thanks for the info, Matt. In the meantime, I also found the following in
the Microsoft FAT32 File System Specification
<http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx>:

| Long names are limited to 255 characters, not including the trailing
| NUL. The total path length of a long name cannot exceed 260 characters,
| including the trailing NUL.

This is especially interesting, because it makes clear that the 260
characters are counted by including the trailing 0.

So concerning full path names on FAT32, Eu's open() function will not
work with legitimate lengths of 255 to 259 characters. Although it might
be somewhat unlikely to encounter this problem, i can happen (as it did
to me). So maybe a future version of Eu can support the maximum allowed
length of 259 characters?

Since Windows has the API function GetShortPathName for converting long
path and file names into short ones, I think I'll also try something
like this:
if length(name) > 254 then
   name = GetShortPathName(name)
end if
fn = open(name, "r")

Regards,
   Juergen

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu