Click here to Skip to main content
Sign Up to vote bad
good
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:48
SIFNOk770

Comments
n.podbielski - 3 Oct '12 - 3:35
So what's the problem really? Are you having some errors? And I think you sould use System.IO.Directory.Exists not file

2 solutions

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  
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 - 13 Mar '13 - 11:46
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
Your Filters
Interested
Ignored
     
0 OriginalGriff 253
1 Rohan Leuva 220
2 Abhinav S 168
3 Mahesh Bailwal 165
4 Ron Beyer 160
0 Sergey Alexandrovich Kryukov 8,528
1 OriginalGriff 6,819
2 CPallini 3,603
3 Rohan Leuva 2,923
4 Maciej Los 2,268


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 8 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid