Reputation: 172
That's my first question and I'm trying my best to describe it.
I would want to create a test file in Windows 7 (and newer; possibly version independent) on NTFS (optionally on FAT32 as well) partition, which name+path will exceed 260 chars limit. I know some 3rd party tools which would do it, but I would want some built-in way.
The problem I'm dealing with a bug reported by me in Firefox caused by such files in Firefox, which needs to be tested by developers (https://bugzilla.mozilla.org/show_bug.cgi?id=1216766). I don't want to force anybody to install 3rd party tool. I tried ways I could think of:
echo foo > c:\[long string]\foo.txt
echo foo > \\?\c:\[long string]\foo.txt
fsutil file createnew c:\[long string]\foo.txt 1
But in these cases Windows failed because limits.
Edit: The file have to be placed directly in Firefox directory (mostly 33-39 characters), so file would have to be over 221-227 chars long.
Edit2: I choosed answer with .NET example, yet I wonder if one could find way for non-programmer, purely in Windows command line/GUI. If it could be done at all, then probably by some bug.
Upvotes: 2
Views: 2706
Reputation: 36318
robocopy
automatically supports long paths, so one simple solution would be to create a file with a long name (221 characters+) in the root directory and then say
robocopy c:\ "C:\Program Files (x86)\Mozilla Firefox" longname*
(Here I'm assuming the name of the file starts with longname
.)
Upvotes: 2
Reputation: 51413
The easiest way is to call the Unicode version of the CreateFile API, prefixing the filename with \\?\
:
std::wstring filename = L"\\\\?\\C:\\<insert up to 32k characters>";
::CreateFileW( filename.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL );
Keep in mind, though, that the shell (namely Explorer.exe) imposes a pathname limit of 260 characters. A file created with a pathname that exceeds this limits cannot be opened, copied, moved, or even deleted using the shell, or any tool using the Shell Path Handling Functions. You can delete the file calling the DeleteFile API.
Upvotes: 4
Reputation: 150108
You can accomplish this using the Unicode version of the Windows APIs. See
for a full description with code.
.NET APIs depend heavily on the Windows APIs, so based on these definitions, it may sound like long paths are immediately out of the question. However, the Windows file APIs provide a way to get around this limitation. If you prefix the file name with "\?\" and call the Unicode versions of the Windows APIs, then you can use file names up to 32K characters in length
I suspect that the code in Firefox exhibiting the bug behavior does not support the \\?\
prefix.
Upvotes: 0
Reputation: 588
Perhaps you can write a .bat file:
@echo off
set LNG = 01234567890123456789012345678901
md %LNG%
cd %LNG%
md %LNG%
cd %LNG%
md %LNG%
cd %LNG%
md %LNG%
cd %LNG%
md %LNG%
cd %LNG%
md %LNG%
cd %LNG%
...
Upvotes: 0