Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Im begginer to C, currently have to learn C and Win32 API, and in my first project i need to get from the user a path name and a file name, then check if the file exists and delete it if the user wants to.

Im currently stuck at finding whether a file exists. Im familiar with a solution that was shown in this site before (What's the best way to check if a file exists in C?) but I have been hinted/instructed to use a function called getfullpathname() in order to parse the strings and then checking if the file entered exists. My problem is that all GetFullPathName does as far as i searched (tried to understand the MSDN and couple or more sites) is concatinating the working drive and directory onto the filename you've provided. Am i missing something? Do i need to change the working directory to the path entered in order to concatinate the path and the name file or just pass to the function the path for it to parse it so i could be able to do the checking? Do i need this function only for parsing the path or to concatinate the path string and the name string? Could you provide me with the example of doing this first part of the project?

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
155 views
Welcome To Ask or Share your Answers For Others

1 Answer

concatinating the working drive and directory onto the filename you've provided.

Not a simple concatenating, This function does not check if the file exists, but just parse the relative path of the file(no matter whether the file exists) to the absolute path. The first parameter of Function GetFullPathName is relative path of the file you need to put in. If the file is located under the current working directory, you only need to send the filename to the function call. If the file is located in the upper path, then you can send ../filename, the function will parse it to an absolute file path.

You could use GetShortPathName. If the file does not exist, the call will fail, and return 0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...