Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

winapi

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

like image 704
na1s Avatar asked Aug 20 '10 08:08

na1s


People also ask

What does \\ mean in Windows path?

UNC paths. Universal naming convention (UNC) paths, which are used to access network resources, have the following format: A server or host name, which is prefaced by \\ . The server name can be a NetBIOS machine name or an IP/FQDN address (IPv4 as well as v6 are supported).

How do I find a file path?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

How do I find a file path in R?

If we want to check the current directory of the R script, we can use getwd( ) function. For getwd( ), no need to pass any parameters. If we run this function we will get the current working directory or current path of the R script. To change the current working directory we need to use a function called setwd( ).

How do I find a directory in C++?

C++ program to find a specific file in a directory opendir-It will open directory stream and take a string as a parameter and return pointer of type DIR if it successfully opens directory or returns a NULL pointer if it is not able to open directory. closedir-It will close the directory.


3 Answers

Use GetFileAttributes.

Edit: You can also check SHGetFileInfo

like image 194
mmonem Avatar answered Sep 23 '22 10:09

mmonem


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

like image 33
cubic1271 Avatar answered Sep 25 '22 10:09

cubic1271


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.

like image 20
JustBoo Avatar answered Sep 21 '22 10:09

JustBoo