10 Replies - 6488 Views - Last Post: 16 June 2011 - 07:13 PM Rate Topic: -----

#1 zippp  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 76
  • Joined: 22-June 09

Checking if directory exists

Posted 15 June 2011 - 03:44 AM

Hi guys.
I'm using then next method to check if a directory exists but it seems it doesn't work. Any ideas?
Imports System.IO

Dim p1 as String = "C:\Program Files"
If Directory.Exists(p1) Then
Msgbox("It's there")
End If


This post has been edited by zippp: 15 June 2011 - 03:49 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Checking if directory exists

#2 Nightfish  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 74
  • View blog
  • Posts: 158
  • Joined: 24-May 11

Re: Checking if directory exists

Posted 15 June 2011 - 03:52 AM

Imports System.IO

        Dim p1 As String = "C:\Program Files"
        If Directory.Exists(p1) Then
            MessageBox.Show("It's there")
        End If



Works for me. Note that I changed the line with the message box. Not sure what yours was supposed to do?

This post has been edited by Nightfish: 15 June 2011 - 03:53 AM

Was This Post Helpful? 0
  • +
  • -

#3 zippp  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 76
  • Joined: 22-June 09

Re: Checking if directory exists

Posted 15 June 2011 - 10:07 PM

It doesn't for me but i got a new method.

Dim myD As String = "C:\Program Files"
Dim DIR As New DirectoryInfo(myD)

If Not DIR.Exists Then

Else

End If



:D
Was This Post Helpful? 0
  • +
  • -

#4 Nightfish  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 74
  • View blog
  • Posts: 158
  • Joined: 24-May 11

Re: Checking if directory exists

Posted 15 June 2011 - 10:22 PM

That is very strange. That first snippet really does work for me, I just checked again. Perhaps we're using different versions of vb.net and there's something fishy going on there.
Was This Post Helpful? 0
  • +
  • -

#5 zippp  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 76
  • Joined: 22-June 09

Re: Checking if directory exists

Posted 16 June 2011 - 02:44 AM

I'm using 2008.
Was This Post Helpful? 0
  • +
  • -

#6 Jeff H  Icon User is offline

  • D.I.C Regular

Reputation: 112
  • View blog
  • Posts: 308
  • Joined: 30-January 11

Re: Checking if directory exists

Posted 16 June 2011 - 03:15 AM

It should work in VS2008,
Directory is basicly the static or shared version of DirectoryInfo.

When you say it does not work do you get a error message and if so what is the message.
Was This Post Helpful? 0
  • +
  • -

#7 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Checking if directory exists

Posted 16 June 2011 - 04:32 AM

Just out of interest, is the first code in form_load or not? If so, try putting it somewhere else and seeing if it works.
Was This Post Helpful? 0
  • +
  • -

#8 Nightfish  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 74
  • View blog
  • Posts: 158
  • Joined: 24-May 11

Re: Checking if directory exists

Posted 16 June 2011 - 04:49 AM

For reference, I did my testing in vb 2010 and on loading the form. That worked fine.
Was This Post Helpful? 0
  • +
  • -

#9 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: Checking if directory exists

Posted 16 June 2011 - 05:56 AM

Msgbox("It's there")



Some code from the good ol' days of VB6. :)
Was This Post Helpful? 0
  • +
  • -

#10 zippp  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 76
  • Joined: 22-June 09

Re: Checking if directory exists

Posted 16 June 2011 - 09:16 AM

View Posttrevster344, on 16 June 2011 - 06:56 AM, said:

Msgbox("It's there")



Some code from the good ol' days of VB6. :)

That's not the problem. I just directly wrote it here. I didn't copy/paste. And yea it's VB 6 :D
Anyway that 1st code isn't working for me at all... Don't know why. No errors, nothing.

LE: Anyway the 2nd one looks more fancy :D

This post has been edited by zippp: 16 June 2011 - 09:19 AM

Was This Post Helpful? 0
  • +
  • -

#11 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: Checking if directory exists

Posted 16 June 2011 - 07:13 PM

View Postzippp, on 16 June 2011 - 09:16 AM, said:

View Posttrevster344, on 16 June 2011 - 06:56 AM, said:

Msgbox("It's there")



Some code from the good ol' days of VB6. :)

That's not the problem. I just directly wrote it here. I didn't copy/paste. And yea it's VB 6 :D
Anyway that 1st code isn't working for me at all... Don't know why. No errors, nothing.

LE: Anyway the 2nd one looks more fancy :D


I wasn't saying it was. :) Otherwise I would have directly wrote it there. ;) I was just making a comment at the old syntax, I still use it as well.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1