Results 1 to 7 of 7

Thread: [RESOLVED] Problems with creating directory

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Resolved [RESOLVED] Problems with creating directory

    I tried this code:

    Code:
    Imports System.IO
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Directory.Exists("c:\testDir1") Then
                'shows message if testdir1 exist
                MsgBox("Directory 'testDir' Exist ")
            Else
                'create the directory testDir1
                Directory.CreateDirectory("c:\testDir1")
                MsgBox("testDir1 created ! ")
                'create the directory testDir2
                Directory.CreateDirectory("c:\testDir1\testDir2")
                MsgBox("testDir2 created ! ")
                'move the directory testDir2 as testDir in c:\
                Directory.Move("c:\testDir1\testDir2", "c:\testDir")
                MsgBox("testDir2 moved ")
                'delete the directory testDir1
                Directory.Delete("c:\testDir1")
                MsgBox("testDir1 deleted ")
            End If
        End Sub
    End Class

    i am getting errors such as:

    Code:
    Exists is not a member of directory
              CreateDirectory is not a member of directory....... and so on
    how to remove these errors?

    thank you

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Problems with creating directory

    It ought to work the way you've shown it so I think there must be something you are not showing us. This perhaps?
    Code:
    Private Class Directory
    End Class
    If you have that in your code, the compiler will look there instead of in System.IO. You could get rid of the errors by giving an unambiguous reference, for example:
    Code:
    If System.IO.Directory.Exists(path) ..
    Or change the name of your own Directory object. Did I guess right?

    bye, BB

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Re: Problems with creating directory

    hi bb,

    i pasted exactly the same code that id did in my project.........

    to remove the bug i just placed an IO before all the Directory...........i.e,IO.Directory.Exists,IO.Directory.CreateDirectory and so on...........

    Can you say why is it behaving like this?

  4. #4
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: Problems with creating directory

    you need to import the system.io namespace

    make sure that it is included in your app properties/references/imported namespaces
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Question Re: Problems with creating directory

    Quote Originally Posted by Megalith View Post
    make sure that it is included in your app properties/references/imported namespaces
    what do you mean by this?

    you can see my first post where i imported System.IO

    but i cant understand what you meant by the above.............

    need your help

    thank you

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Question Re: Problems with creating directory

    ok now i did this:
    Name:  Untitled.png
Views: 99
Size:  10.9 KB

    then i did exactly the same code that i gave in the first post,but still the same problem..............it tells

    exists is not a member of directory

    for this particular line od the code:

    Code:
    Directory.exists("C:\testDir")
    need some help

    thank you

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Problems with creating directory

    I don't have access to vb.net at the moment so I typed this in Notepad so please amend the syntax errors if any...

    Could you tell me what do you get when you use this code?

    Code:
    Imports System.IO
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
            MsgBox DirExst("C:\testDir1")
        End Sub
    
        Public Function DirExst(ByVal Path As String) As Boolean
            On Error Resume Next
            Dim myIO As New FileInfo(Path)
            If Not myIO.Exists() Then
                myIO = New DirectoryInfo(Path)
            End If
            Return myIO.Exists()
        End Function
    End Class
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width