Page 1 of 1

Error 206 The filename or extension is too long

Posted: 26 Feb 2006, 01:27
by Stefan von Allmen
I would like to bring something to your attention which might help to improve Servant Salamander.

With ordinary path names, Windows API is limited to a maximum path length of 260 characters. You might however avoid this limit by prepending \\?\ to the fully qualified path name for local files (i.e \\?\C:\WINDOWS\Win.ini) or replace the initial \\ by \\?\UNC\ for an UNC path (i.e. \\?\UNC\Server\Share\File.ext). By doing so, the maximum path length is at around 32000 characters

This can circumvent the error mentioned in the subject.

Posted: 26 Feb 2006, 08:20
by Jan Rysavy
Moderator: moved to Feature Requests.

Posted: 28 Feb 2006, 23:07
by thehappyhippo
I support this request. I got no error message, but the limitation occures by subdirectories with a path length larger than 260 characters. This is often the case on network shares (e.g Sama export of UNIX volumes).

I have written a small program that demonstrates the problem. This program creates 20 subdirectories "a" and an file (filexx.txt) in each directory. Then the directories are renamed upwards to a 20 character long name. At the top level the program tries to open the file at the lowest level directory (file19.txt) with CreateFileW and with the \\?\ prefix.

With SS and Explorer you should not able to reach a directory lower then level 10 (file10.txt).

The program started with d renames the directories to the short names, so you can delete it.

Here is the code:

Code: Select all

  Demonstrates usage of CreateFile with paths longer than MAX_PATH
  SS should implement this feature on W2K and newer Windows versions
  The auhtor does not accept any WARRANTY for direct or indirect damages caused by this program.
  Use it at your own risk!
  see also
#include <windows.h>
#include <tchar.h>
#include <stdio.h>

#define PATHLENGTH 20*20+30

void printErrorAndExit(const char *msg, DWORD err)
	LPSTR lpMsgBuf;
					  (LPSTR) &lpMsgBuf,
					  NULL ))
		fprintf(stderr,"%s : %s\n",msg,lpMsgBuf);
		fprintf(stderr,"Error at FormatMesage: %d\n",err=GetLastError());

int main(int argc, char *argv[])
    int i;
    wchar_t tmp[100];
    wchar_t *path;
    wchar_t *upath;
    wchar_t *curdir;
    HANDLE f;
        fprintf(stderr,"%s\nusage: c(reate)|d(delete)\n",argv[0]);
                DWORD written;
                if(!CreateDirectoryW(L"a",NULL)) //create new dir a
                if(!SetCurrentDirectoryW(L"a")) //change to a
                swprintf(tmp,L"file%2d.txt",i); //create file
            for(i=0;i<20;i++) //rename Directories recursiv
                SetCurrentDirectoryW(L"..");//go upwards
                if(!MoveFileW(L"a",L"01234567890123456789")) /* rename Directory to 20 long name */
            /* now 20*20+19*Backslash + Basedirectory >> MAX_PATH */
            DWORD len=0;
            len=GetCurrentDirectoryW(len,NULL); //get Basedirectory
            curdir=new wchar_t[len+1]; 
            path=new wchar_t[PATHLENGTH+len+10];
            //now the file10.txt exceeds MAX_PATH
                if(i==0) //build the complete path to file19.txt
            wcscat(path,L"file19.txt"); // add file name 
            wprintf(L"Try to open %s\n",path);
            // try to open the normal way, should not work !!!
                printErrorAndExit("CreateFile 1",GetLastError());
            upath=new wchar_t[wcslen(path)+4];
            swprintf(upath,L"\\\\?\\%s",path); // use UNICODE path prefix, works also for networkshares
            wprintf(L"Try to open %s\n",upath);
            // open with unicode prefix, allows 32k path length
                printErrorAndExit("CreateFile 2",GetLastError());
            // should work
            delete curdir;
            delete upath;
            delete path;
        else if(*argv[1]=='d') // rename the directories to short names
        { //rename to a
                    printErrorAndExit("MoveFile 1",GetLastError());
                     printErrorAndExit("SetCurrentDirectory 1",GetLastError());
            //now you can delete the directories
    return 0;        

Posted: 01 Mar 2006, 10:58
by Petr Solin
I know about this NTFS feature, but at least for now I think it would not be reasonable to support it, because most of applications can't work with such extra-long file names (neither Windows Explorer - at least under WinXP). Moreover not all Win32 API functions support this extra-long path format, so it will probably lead us to some unexpected troubles.

I have added support for working with too long file names on not too long pathes (less than 260 characters) to current working version of Salamander. It's based on dos-file-names (it works only if path length plus 12 characters (8.3 names) is less than 260 characters). Windows Explorer under WinXP uses the same thing.

Re: Error 206 The filename or extension is too long

Posted: 03 Sep 2010, 23:30
by wqw

Re: Error 206 The filename or extension is too long

Posted: 04 Sep 2010, 01:30
by therube
To take advantage of auto path shrinking, you do need to not turn off short name generation.
And then it goes to link to an article, which shows four possible values.
And if you search you will find other articles, which shows two possible values.

So what settings you can use depends on OS ...

And then some more searching turns up (older articles):
If you have not installed any 16-bit applications on a Windows NT-based computer, you can turn off automatic short (8-character name, 3-character extension) file name generation to speed up file and folder access on your computer running Windows NT.
Which kind of implies that if you have pre-existing 16-bit apps installed, it would bugger up such apps, as presumably they do store SFN in the Windows Registry?

So things may not be as simple as that.

Not to mention if I turned off 8.3, when I fire up Norton Commander 5.0 (DOS), what would I see ;-)?

Re: Error 206 The filename or extension is too long

Posted: 05 Sep 2010, 16:50
by SvA
Therube, you misread:
To take advantage of auto path shrinking, you do need to not turn off short name generation.
8dot3names are required for this "auto path shrinking" to work.

Re: Error 206 The filename or extension is too long

Posted: 06 Sep 2010, 13:52
by therube
Heh. You're right. (And I read that a number of times because it was confusing to me.)

Re: Error 206 The filename or extension is too long

Posted: 18 Apr 2011, 21:56
by roman2
I have to resort to using Windows Explorer when dealing with very long paths. When will this be addressed?