Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Verify a path ...

Posted on 1998-03-12
Last Modified: 2013-12-26
How to verify if a path is a valid path (a path that exist) ?
Question by:Alexander
  • 2
  • 2

Expert Comment

ID: 1299585
1) Call OpenFile (.., .., OF_EXIST)
2) Call FindFirstFile (.., &a_win32finddata_struct)
   // don't forget to call FindClose () on the returned handle,
   // if it's not INVALID_HANDLE_VALUE
2) Call GetShortPathName (...)

Author Comment

ID: 1299586
Sorry but i dont want to check if a file exist in a path but only if the path exist. If one of those functions do that can you be more explicit ?
Thank you !

Accepted Solution

dabbler earned 70 total points
ID: 1299587
All of those functions will work for either a file *or* a directory.  Just call them with the full path of the directory.  E.g., to see if path "C:\\Bamboo\\Slivers" exists, call FindFirstFile ("C:\\Bamboo\\Slivers", &wfd) and see if it returns a valid handle.  Then close the handle.

Author Comment

ID: 1299588
ok, thank you, but finally i've used the SetCurrentDirectory function, because i need to change too, if the directory exist !


Expert Comment

ID: 23423009
Isn't this better?

                    System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(stringPath);

                    bValidFile = di.Exists;

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
RSS Feeds--IE 13 185
Disabling automatic web page translations 9 53
Swiper slider stops between pages 11 51
Re-position the objects 7 117
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question