Click here to Skip to main content
13,355,726 members (60,344 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi All,

i was wondering if anyone could assist. i have a form with 2 listbox, that allows user to enter in a directory path that is then populated in to the listbox1. I have a button on the form that i want to be able to press which cycle through the listbox items and checks if the directory exists.

i was thinking it would be something along the lines of :
For Each something In listbox1

if = false then
      'in second listbox display missing directory
    listbox2.item.add("does not exist " & somethinghere2)
        'if the directory does exist
       'do nothing
end if


this is for purpose to help me with my job, so i dont have to manually check if users have deleted directories overnite.... im not much of a programmer but any help would be great.
Posted 2-Oct-12 21:48pm
n.podbielski 3-Oct-12 3:35am
So what's the problem really? Are you having some errors?

And I think you sould use System.IO.Directory.Exists not file
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you're going to check if a directory exists, you should use

System.IO.Directory.Exists() function which returns True if the directory exists and False otherwise.

If you're going to check if a file exists, you should use

System.IO.File.Exists() function.

If you want to iterate through all files in a directory, you should use

System.IO.Directory.GetFiles(string path)

Check Microsoft's documentation on System.IO.Directory
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

For a simple solution to check if directory is exist just try this simple code
If Dir("yourdirectory") = "" Then
 ' does not exist
End If
Sergey Alexandrovich Kryukov 13-Mar-13 11:46am
Have a shame! It's totally wrong. You need to try code if you want to post an answer.
Votes 2.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100