tags:

views:

48

answers:

3

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

A: 

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

cubic1271
Something else that may be useful: http://api.farmanager.com/en/winapi/win32_find_data.html [explanation of WIN32_FIND_DATA structure].
cubic1271
But how to check is file path a disk?
na1s
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.
JustBoo
+2  A: 

Use GetFileAttributes.

Edit: You can also check SHGetFileInfo

mmonem
But how to check is file path a disk?
na1s
Simply, a disk is a path that ends with a colon
mmonem
I think it is possible to check by WINAPI
na1s
@na1s Check the updated answer
mmonem
+1  A: 

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.

JustBoo