Solved

Cannot open long file path

Posted on 2013-01-27
7
695 Views
Last Modified: 2013-01-28
Hello Experts,

I cannot open long file path with _wfopen_s() and FindFirstFile().

A long file path means "C:\aaaaaaa....\bbbbb....txt"(260 bytes).

Windows 7 32bit, C++Builder XE2

Please advice.
0
Comment
Question by:NobMiwa
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 38825834
in C++ "\a" is an alert character, and "\b" is a backspace character.
Did you mean  "C:\\aaaaaaa....\\bbbbb....txt"?
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 38825837
Hi MobMiwa,

take a look at the section Maximum Path Length Limitation in this article: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx

There you can find the maximum length for a path is 260 incluind drive letter and terminating NUL character.

To use longer paths you have to use the UNICODE versions of the functions and prefix the path with a \\?\. According to ozo's comment you path should then look like i.e. this: "\\\\?\\C:\\aaaaaaa....\\bbbbb....txt".

Hope that helps,

ZOPPO
0
 

Author Comment

by:NobMiwa
ID: 38825838
Thank you for reply.

Yes, I mean "C:\\aaaaaaa....\\bbbbb....txt" in code.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:NobMiwa
ID: 38825854
Thank you for reply ZOPPO.

What do you mean "UNICODE versions of the functions" ?
Can I use _wfopen_s() ? If not, how can I open and read a file ?
0
 
LVL 15

Expert Comment

by:Minh Võ Công
ID: 38825890
Yes, I mean "C:\\aaaaaaa....\\bbbbb....txt" in code -> you can try the full path file, example "C\\aaaaaaaaaaaaaa\\bbbbbbbbb.txt,
you can use "C:\\aaaaaaa....\\bbbbb....txt" in console application.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 38825914
Hm - I'm not really sure because I never used it this way, but I guess it should work with _wfopen_s since this is a wide-character version of fopen_s.

If it doesn't work you can use API functions like CreateFileW/ReadFileW/WriteFileW and FindFirstFileW/FindNextFileW/FindClose if your application doesn't use UNICODE.

ZOPPO
0
 

Author Closing Comment

by:NobMiwa
ID: 38826925
Thank you for super quick reply !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 76
Please explain "Promise Pattern" and how it's used 2 54
creating threads in delphi 1 82
Not needed 13 93
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now