Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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 :
VB
For Each something In listbox1

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

   Next


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
Comments
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

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
 
Share this answer
 
For a simple solution to check if directory is exist just try this simple code
If Dir("yourdirectory") = "" Then
 ' does not exist
End If
 
Share this answer
 
Comments
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.
—SA

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900