CreateFile and Long Path/Files :: Win32
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: CreateFile and Long Path/Files :: Win32

  1. #1
    Join Date
    Feb 2002
    Posts
    5,758

    CreateFile and Long Path/Files :: Win32

    Hi.

    Is it possible to create a file with a long path name? For example:

    Code:
    std::string pathFile("c:\testing\December 27\newfile.type");
    
    // CreateFile fails
    if (::CreateFile(pathFile->c_str(),...) == INVALID_HANDLE_VALUE)
    {
    }
    I would like to know two properties of CreateFile(). First, is it possible to create a file in a directory that does not exist via CreateFile()? In the example above, directories "testing" and "December 27" do not exist.

    Secondly, is it possible to create directories with spaces between one or more words, i.e. December 27. Notice the space before "2."

    Thanks,
    Kuphryn
    Share on Google+

  2. #2
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097
    You must create the path if it does not exist. CreateFILE does exactly what it states.

    There is no problem with long filenames or even names with spaces.

    Hope this helps....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first
    Share on Google+

  3. #3
    Join Date
    Feb 2002
    Posts
    5,758
    Okay. Thanks.

    Kuphryn
    Share on Google+

  4. #4
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: CreateFile and Long Path/Files :: Win32

    Originally posted by kuphryn
    Code:
    std::string pathFile("c:\testing\December 27\newfile.type");
    Assuming that the directories exist, if you have problems with this, then it is because you need to use the following instead:
    Code:
    std::string pathFile("c:\\testing\\December 27\\newfile.type");
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor
    Share on Google+

  5. #5
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097
    Slapping myself silly...Didnt notice the single back slashes, not cuaght since the next character in the string is a valid escapped character (but illegal in a filename of course!).
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first
    Share on Google+

  6. #6
    Join Date
    May 2014
    Posts
    4

    Re: CreateFile and Long Path/Files :: Win32

    You may use Long Path Tool for this purpose. Its sure to sort out your problem.
    Share on Google+

  7. #7
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,051

    Re: CreateFile and Long Path/Files :: Win32

    Quote Originally Posted by adamenko View Post
    You may use Long Path Tool for this purpose. Its sure to sort out your problem.
    No, there is not necessary a special tool to create such "long" path files as shown in the OP.
    Besides, note this topic is 12 years old.
    Please, do not resuscitate old threads!
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center