Results 1 to 8 of 8

Thread: folder exist ???

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86

    Resolved folder exist ???

    can someone tell me how i can see if a folder exist or not

    is use this to find a file

    if len(dir$("login.dat")) > 0 then

    i could not find the right script to o the same for a folder
    i try't this

    if len(mkdir$("login")) > 0 then


    but an error shows up then

    what's is the right way to do this
    Last edited by davyquyo; Oct 19th, 2004 at 09:39 AM.

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989
    I have searched for this alot and I find these to be the best:

    VB Code:
    1. Function funFolderExists(ByVal lsFilename As String) As Boolean
    2.         On Error Resume Next
    3.        
    4.         Dim fso As New Scripting.FileSystemObject
    5.        
    6.         funFolderExists = fso.FolderExists(lsFilename)
    7.         Set fso = Nothing
    8.     End Function
    9.    
    10.     Function funFileExists(ByVal lsFilename As String) As Boolean
    11.         On Error Resume Next
    12.        
    13.         Dim fso As New Scripting.FileSystemObject
    14.        
    15.         funFileExists = fso.FileExists(lsFilename)
    16.         Set fso = Nothing
    17.     End Function

    you have to turn on Microsoft Scripting Runtime in the refferences.

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    VB Code:
    1. 'check for a folder existance
    2. If Dir(App.Path & "\Data", vbDirectory) = "" Then
    3.     MkDir App.Path & "\Data"
    4. Else
    5.     'check for a file existance
    6.     If Not Dir(App.Path & "\Data\myfile.dat", vbNormal) = "" Then
    7.         'open file
    8.     Else
    9.         MsgBox "Cannot locate " & App.Path & "\Data\myfile.dat"
    10.     End If
    11. End If

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    i think the one from redbull is the bestpassing thing to my script
    i try not to use fso
    don't ask me why
    probaply because i can use fso in html on local machine and i will mix up the scripts
    hehe

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Sorry, I know this thread is resolved but a more reliable way without
    dependancies to check for a file...

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const OF_EXIST = &H4000
    4. Private Const OFS_MAXPATHNAME = 128
    5.  
    6. Private Type OFSTRUCT
    7.     cBytes As Byte
    8.     fFixedDisk As Byte
    9.     nErrCode As Integer
    10.     Reserved1 As Integer
    11.     Reserved2 As Integer
    12.     szPathName(OFS_MAXPATHNAME) As Byte
    13. End Type
    14.  
    15. Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
    16.  
    17. Public Function FileExists(ByVal sFile As String) As Long
    18.  
    19.     Dim lRetVal As Long
    20.     Dim OfSt As OFSTRUCT
    21.    
    22.     lRetVal = OpenFile(sFile, OfSt, OF_EXIST)
    23.     If lRetVal = 1 Then
    24.         FileExists = 1
    25.     Else
    26.         FileExists = 0
    27.     End If
    28.    
    29. End Function
    30.  
    31. 'Usage:
    32. Private Sub Command1_Click()
    33.     If FileExists("C:\DeleteMe\Test.txt") = 1 Then
    34.         Msgbox "File Exists!"
    35.     Else
    36.         MsgBox "File Not Found!"
    37.     End If
    38. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    it's realy very nice but here you going to use dll
    i also try not to use much dll files because i want to try avoid dll trouble
    i don't wan't to be responsible
    that a computer from a great company crashes

    thanks for the help

  7. #7
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989
    The reason I ended up using FSO (I can remember I think I started a thread on this) is that the method that Rhino gave (which I used at first) does not work with hidden folders. I tested 4 different methods and the one with FSO is the best, and all you have to include is the scrrun.dll which is only about 140kb

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    kernel32 is a basic Windows O.S. dll. If the user doesn't have it
    then they are not running Windows NT 3.1 or later or Windows
    95 or later.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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