Reputation: 619
I want to pragmatically create a folder hierarchy. But the problems is in some cases the folder name comes beyond 260 characters and the folder creation getting failed. I have created this folder hierarchy using Win32 File Namespaces. I want to create a folder structure in the following format. DRIVE_LETTER:\FOLDER1\FOLDER2\FOLDER3\FOLDER4........\FOLDER(N-1)\FOLDER(N)
FOLDER1, FOLDER2, FOLDER3 etc are names of the folder. These names are of length more than 260 characters for eg:
FOLDER1 name is qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm
FOLDER2 name is mnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewqmnbvcxzlkjhgfdsapoiuytrewq
like this will go.
How can I over come this folder name/file name name length constraint.
The OS : Windows 7 64 bit and Windows Server 2008 R2 64 bit.
Please help
Upvotes: 2
Views: 5652
Reputation: 25288
A single path component (e.g. a folder name or file name) is limited by the value of MaximumComponentLength
returned by GetVolumeInformation
. This is in theory filesystem-specific but in practice is always 255.
So, you can't do what you asked unless you make your own filesystem driver which supports longer file components. What you can do, however is to create a path with total length longer than 260 characters, as has been pointer in other answers.
Upvotes: 1
Reputation: 69672
MSDN's CreateDirectory function explains you exactly this:
To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend
\\?\
to the path. For more information, see Naming a File.
See also: Should I deal with files longer than MAX_PATH?
NTFS support filenames up to 32K (32,767 wide characters). You need only use correct API and correct syntax of filenames. The base rule is: the filename should start with
\\?\
like\\?\C:\Temp
. The same syntax you can use with UNC:\\?\Server\share\Path
.
Upvotes: 2
Reputation: 7495
You can use one of these two tricks:
C:\folder1\folder2\...\folder20
, you can create C:\folder19
, C:\folder20
and then move folder20
with all its subfolders into C:\folder19
, then create C:\folder18
and move C:\folder19
with folder20
inside C:\folder18
. Repeat until you finished creating this structure.\\?\C:\folder1\folder2\...\folder20
notation to create your path. More information is here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx (search for words Maximum Path Length Limitation).Upvotes: 1