|
-
Oct 19th, 2004, 08:51 AM
#1
Thread Starter
Lively Member
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.
-
Oct 19th, 2004, 08:54 AM
#2
I have searched for this alot and I find these to be the best:
VB Code:
Function funFolderExists(ByVal lsFilename As String) As Boolean
On Error Resume Next
Dim fso As New Scripting.FileSystemObject
funFolderExists = fso.FolderExists(lsFilename)
Set fso = Nothing
End Function
Function funFileExists(ByVal lsFilename As String) As Boolean
On Error Resume Next
Dim fso As New Scripting.FileSystemObject
funFileExists = fso.FileExists(lsFilename)
Set fso = Nothing
End Function
you have to turn on Microsoft Scripting Runtime in the refferences.
-
Oct 19th, 2004, 08:56 AM
#3
VB Code:
'check for a folder existance
If Dir(App.Path & "\Data", vbDirectory) = "" Then
MkDir App.Path & "\Data"
Else
'check for a file existance
If Not Dir(App.Path & "\Data\myfile.dat", vbNormal) = "" Then
'open file
Else
MsgBox "Cannot locate " & App.Path & "\Data\myfile.dat"
End If
End If
-
Oct 19th, 2004, 09:23 AM
#4
Thread Starter
Lively Member
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
-
Oct 19th, 2004, 10:34 AM
#5
Sorry, I know this thread is resolved but a more reliable way without
dependancies to check for a file...
VB Code:
Option Explicit
Private Const OF_EXIST = &H4000
Private Const OFS_MAXPATHNAME = 128
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Public Function FileExists(ByVal sFile As String) As Long
Dim lRetVal As Long
Dim OfSt As OFSTRUCT
lRetVal = OpenFile(sFile, OfSt, OF_EXIST)
If lRetVal = 1 Then
FileExists = 1
Else
FileExists = 0
End If
End Function
'Usage:
Private Sub Command1_Click()
If FileExists("C:\DeleteMe\Test.txt") = 1 Then
Msgbox "File Exists!"
Else
MsgBox "File Not Found!"
End If
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 19th, 2004, 11:51 AM
#6
Thread Starter
Lively Member
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
-
Oct 19th, 2004, 12:12 PM
#7
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
-
Oct 19th, 2004, 12:34 PM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|