Windows CreateFile method and long file names

  • Thread starter Thread starter duraisridhar
  • Start date Start date
D

duraisridhar

Hi All,

I'm creating a file with long filename (more then 200 chars ) in
Windows system using CreateFile method by prepending "\\?\" in the
file name( as suggested in MSDN). The files is created successfully,
but I could not open the file by clicking the file. Even the "open"
menu in the right click is not working. The Right click shows only
two options - "open", "send to". Other options/menus like
"Properties" , "Copy", "Rename", "Paste" etc ., menu is not shown.

When File name is smaller (less then 150 chars) , my code works
without any problem and I can open the file, can see the "Properties"
and other menus when I right click.

Could you guess where i going wrong ?. What options should I use so
that I can see all right click options. For your reference, I paste
snip of my code,


HANDLE fileHandle = CreateFile("\\?\D:\LongFileName\<fileName with
230 Chars>.txt ",
GENERIC_READ |
GENERIC_WRITE,
FILE_SHARE_READ,
NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);

Any help on this will be greatly appreciated.

Regards,
Sri
 
* (e-mail address removed):
Hi All,

I'm creating a file with long filename (more then 200 chars ) in
Windows system using CreateFile method by prepending "\\?\" in the
file name( as suggested in MSDN). The files is created successfully,
but I could not open the file by clicking the file. Even the "open"
menu in the right click is not working. The Right click shows only
two options - "open", "send to". Other options/menus like
"Properties" , "Copy", "Rename", "Paste" etc ., menu is not shown.

When File name is smaller (less then 150 chars) , my code works
without any problem and I can open the file, can see the "Properties"
and other menus when I right click.

Could you guess where i going wrong ?.

yes and so can you otherwise you would not have posted silly question

What options should I use so
that I can see all right click options. For your reference, I paste
snip of my code,

use shorter filename

HANDLE fileHandle = CreateFile("\\?\D:\LongFileName\<fileName with
230 Chars>.txt ",
GENERIC_READ |
GENERIC_WRITE,
FILE_SHARE_READ,
NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);

Any help on this will be greatly appreciated.

cheers

alf
 
hi,
use shorter filename

Are you mentioning about the 8.3 filename created using C++
GetShortPathName() method ???. I have already tried this and it didn't
work. GetShortPathName, GetLongPathName etc., will work iff file
already exists. As i'm creating file freshly, the GetShortPathName
will not work and it just returned NULL.

As a work around, i created the file and i tried SetFileAttributes
with short file name. The SetFileAttributes returned true. Still, the
Right click shows only two options - "open", "send to". Other options/
menus like "Properties" , "Copy", "Rename", "Paste" etc ., menu is
not shown. Also, i couldn't open the file when click it.
yes and so can you otherwise you would not have posted silly question - use shorter filename

I know using shorter file names will resolve this issue. But in my
case, I warranted to use this.

Regards,
Sri
 
Path is only 260 total. It's not clear in your post if the filename or the
total path is 230 chars.

--
..
--
hi,
use shorter filename

Are you mentioning about the 8.3 filename created using C++
GetShortPathName() method ???. I have already tried this and it didn't
work. GetShortPathName, GetLongPathName etc., will work iff file
already exists. As i'm creating file freshly, the GetShortPathName
will not work and it just returned NULL.

As a work around, i created the file and i tried SetFileAttributes
with short file name. The SetFileAttributes returned true. Still, the
Right click shows only two options - "open", "send to". Other options/
menus like "Properties" , "Copy", "Rename", "Paste" etc ., menu is
not shown. Also, i couldn't open the file when click it.
yes and so can you otherwise you would not have posted silly question -
use shorter filename

I know using shorter file names will resolve this issue. But in my
case, I warranted to use this.

Regards,
Sri
 
I'm creating a file with long filename (more then 200 chars ) in
Windows system using CreateFile method  by prepending "\\?\" in the
file name( as suggested in MSDN).  The files is created successfully,
but I could not open the file by clicking the file.  Even the "open"
menu in the right click is not working.  The Right click shows only
two options - "open", "send to". Other options/menus like
"Properties" ,  "Copy", "Rename", "Paste" etc ., menu is not shown.

I think that although the NTFS filesystem can handle long filenames (>
MAX_PATH (200+) chars), the Windows Shell API cannot. Windows
Explorer is based on the shell. So you can create and use really long
filenames programmatically, but you will not be able to browse them
with Windows Explorer, or work with them under the shell api.

From MSDN: "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."
-Andrew.
 
Back
Top