Click here to Skip to main content
11,705,762 members (57,451 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 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 2-Oct-12 20:48pm
SIFNOk816
Comments
n.podbielski at 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
good
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
  Permalink  
Rate this: bad
good
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
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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)

  Print Answers RSS
0 OriginalGriff 218
1 Sergey Alexandrovich Kryukov 170
2 Inimicos 60
3 ProgramFOX 50
4 Richard MacCutchan 45
0 OriginalGriff 9,037
1 Sergey Alexandrovich Kryukov 8,417
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2015
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