Results 1 to 6 of 6

Thread: [RESOLVED] Check if folder exists

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    49

    Resolved [RESOLVED] Check if folder exists

    Hi, Im making a program with a textbox were the user enteres a folder, but if the folder doesn't exist they get an error.
    anyone know how to check if the folder exists?

    Thanks!

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

    Re: Check if folder exists

    Quote Originally Posted by Durthor
    Hi, Im making a program with a textbox were the user enteres a folder, but if the folder doesn't exist they get an error.
    anyone know how to check if the folder exists?

    Thanks!
    Does this help?

    Code:
    'Returns a boolean - True if the folder exists
    Public Function DirExists(MyFile As String)
    Dim fs
    Set fs = CreateObject("Scripting.FileSystemObject")
    DirExists = fs.folderexists(MyFile)
    End Function
    Hope this helps...
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    49

    Re: Check if folder exists

    Quote Originally Posted by koolsid
    Does this help?

    Code:
    'Returns a boolean - True if the folder exists
    Public Function DirExists(MyFile As String)
    Dim fs
    Set fs = CreateObject("Scripting.FileSystemObject")
    DirExists = fs.folderexists(MyFile)
    End Function
    Hope this helps...
    how to use?

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

    Re: Check if folder exists

    Does this help?

    Code:
    'Paste this in a module
    Public Function DirExists(Myfile As String)
        Dim fs
        Set fs = CreateObject("Scripting.FileSystemObject")
        DirExists = fs.folderexists(Myfile)
    End Function
    
    'Paste this either in a module or from whereevr you are calling it...
    Sub aaa()
        Dim Myfile As String
    
        'Change this with the name of the folder
        Myfile = "S:\New Folder"
    
        'if the above folder exists then the msgbox
        'below will return true
        MsgBox DirExists(Myfile)
    End Sub
    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

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    49

    Talking Re: Check if folder exists

    Thanks!!! works perfectly!!!

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Check if folder exists

    Another way. Note, if the folder does already exist, it will do nothing
    Code:
    Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" _
    (ByVal lpPath As String) As Long
    
    Private Sub Command1_Click()
    'the will create the directory "c:\this\is\a\test\directory\"
    'if it doesn't already exist
    MakeSureDirectoryPathExists "c:\this\is\a\test\directory\"
    End Sub

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