directory exists // create

Looking for easy way to check if a directory exist and otherwise to create it


Answer this question

directory exists // create

  • Flavelle Ballem

    Ok than,

    I look a bit further cause the call needs 2 arguments, a construction like this works

    LPSECURITY_ATTRIBUTES attr;
    attr = NULL;
    CreateDirectory("media/Saartje",attr) ;

    But, how do I check if one already exists


  • PsychicDave

    Hello,

    The MSDN page for SHCreateDirectoryEx has this note:
    Note This function is available through Microsoft Windows XP Service Pack 2 (SP2) and Windows Server 2003. It might be altered or unavailable in subsequent versions of Windows.
    It also has this:
    Minimum operating systems: Windows 2000, Windows Millennium Edition

    On the other side, CreateDirectory page has this:

    Client: Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.


    I'd rather use SHCreateDirectoryEx than CreateDirectory, so I'd like to know wether the note is an error on Microsoft side, or that SHCreateDirectoryEx can't be safely used for compatibility reasons.

    Thanks.

  • Tasha O.

    Hi,
    if I'm not mistaken, this is the ansi way for checking if a folder exists:

    struct stat st;
    bool folderExists = (stat("C:\\", &st) == 0);



  • ender080

    CreateDirectory()

    Kuphryn


  • Bells

    Try _taccess method.

    Regards,

    Paresh.


  • Abdul Wajed

    SHCreateDirectoryEx seems to be EOL ( no longer supported )

    If you CreateDirectory is succesfull, you may now have to RemoveDirectory.

    Is there any method that won't change anything but just report the directory exists or not Basically an equivalent to .Net's Directory.Exists but not .NET or like stat but for a directory not a file




  • João Pereira

    SHCreateDirectory(Ex) do a perfect job.

  • directory exists // create