View Single Post
Old 21st March 2011, 02:22   #225  |  Link
mariush
Registered User
 
Join Date: Dec 2008
Posts: 589
It's quite possible to create and work with such files, it's just that you need to use the unicode functions instead of the default ANSI ones. Oh, and I think you have to be sure each segment of the path is below 260 ansi characters.

Here's a code I wrote right now in a few minutes... it's visual basic 6 but uses the windows api:

Code:
Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
End Type

Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2

Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryW" (ByVal lpPathName As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileW" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Sub Form_Load()
Dim ret As Long
Dim s As String
Dim sec As SECURITY_ATTRIBUTES

Const folname As String = "This is a folder with a very long name because I like very long names and nobody can stop me from making them, they are so cool and magical"
Const filname As String = "This is a file with a very long name because I like very long names and nobody can stop me from making them, they are so cool and magical"

ret = CreateDirectory(s, sec)
MsgBox "Created folder " & folname & ", got reply " & CStr(ret) & " (0 means failure)"
s = StrConv("\\?\C:\" & folname & "\" & filname, vbUnicode)
ret = CreateFile(s, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, CREATE_ALWAYS, 0, 0&)
MsgBox "Created file ::" & folname & "::, in the previously created folder, got handle " & CStr(ret)
ret = CloseHandle(ret)
end sub
The result is this:



Total length 281 characters.

Funny though, stuff like echo "1" >"This..." doesn't work, as it won't find the file... same with copy con "this..."

Code:
C:\This is a folder with a very long name because I like very long names and nob
ody can stop me from making them, they are so cool and magical>copy CON "This is
 a file with a very long name because I like very long names and nobody can stop
 me from making them, they are so cool and magical"
The file name is too long.
        0 file(s) copied.
ps. the vb6 "to unicode" functions converts it to utf-16 (two bytes per character) so that may be where you went wrong before if you tried it"

Last edited by mariush; 21st March 2011 at 02:26.
mariush is offline   Reply With Quote