na1s
na1s

Reputation: 177

How to check with WINAPI file path is disk or file or directory?

How to check with WINAPI file path is disk or file or directory?

Upvotes: 7

Views: 6076

Answers (3)

JustBoo
JustBoo

Reputation: 1741

See if the path has a drive letter in front of it? All UNC's take the form "\\server\share\file_path" No drive letter.

Out of curiousity I looked this up. Based on this MSDN article Naming Files, Paths, and Namespaces, it seems my advice is exactly how it says it should be done.

Upvotes: 1

mmonem
mmonem

Reputation: 2831

Use GetFileAttributes.

Edit: You can also check SHGetFileInfo

Upvotes: 7

cubic1271
cubic1271

Reputation: 1138

Could try FindFirstFile:

http://msdn.microsoft.com/en-us/library/aa364418%28v=VS.85%29.aspx

Once you have the find data (passed as the 2nd argument to that function):

if(result->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
    //file is a directory
}
else
{
    //file is not a directory
}

Also, to see if something is a volume, could try something like:

if(result->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
{
    if(result->dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT)
    {
        //path is a volume; try using GetVolumeNameForVolumeMountPoint for info
    }
}

HTH

Upvotes: 4

Related Questions