CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2002
    Posts
    5,757

    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

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    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,2010
    In theory, there is no difference between theory and practice; 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

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

    Kuphryn

  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

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    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,2010
    In theory, there is no difference between theory and practice; 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

  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.

  7. #7
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured