Help need - How to tell if a file exist.

  • Thread starter Thread starter FatMan
  • Start date Start date
F

FatMan

Hi all:
What I need help with is.....

How do I determine if the file name a user types into an InputBox exist?

My overall goal is to have the user type in the file name, check that it is
actualy a valid file on the hard drive and then do my processing on the text
file. I have the processing part just about pegged and will post other
questions for some unresolved issues.

Can anyone tell how to check to see if a file name is valid and that it
exist on the hard drive? I am using Access 2000.

Any help is greatly appreciated it.

Thanks,
FatMan
 
Hi all:
What I need help with is.....

How do I determine if the file name a user types into an InputBox exist?  

My overall goal is to have the user type in the file name, check that it is
actualy a valid file on the hard drive and then do my processing on the text
file.  I have the processing part just about pegged and will post other
questions for some unresolved issues.

Can anyone tell how to check to see if a file name is valid and that it
exist on the hard drive?  I am using Access 2000.

Any help is greatly appreciated it.

Thanks,
FatMan

several options:
strFileName=InputBox("Please enter the full path to the file...")
if Dir(strFileName)<>"" Then
'the file exists
Else
msgbox strFile & " does not exist!", vbokonly+vbinformation
end if

The other option is to use the FileOpenAPI where a user cannot choose
a non-existent file. www.mvps.org/access/api/api0001.htm
 
pietlinden:
Thank you.  Your If/Else statement worked like a charm.

Thanks,
FatMan







- Show quoted text -

Intersting concept!

Is it also possible to then create a new directory if the directory
does not exist?

If so, How do we dothis in code?

I save invoices to PDF and use the Acc No. as Directories.

Thanks

Rocky
 
Dim strFolder As String
Dim strSubfolder As String

strFolder = "C:\Folder1\Folder2\"
strSubfolder = "Subfolder"
If Len(Dir(strFolder & strSubfolder, vbFolder)) > 0 Then
' C:\Folder1\Folder2\Subfolder exists
Else
' C:\Folder1\Folder2\Subfolder doesn't exist.
' Make sure C:\Folder1\Folder2 exists...
If Len(Dir(strFolder, vbFolder)) > 0 Then
' C:\Folder1\Folder2 exists: add the subfolder
MkDir strFolder & strSubfolder
Else
' C:\Folder1\Folder2 doesn't exist.
End If
End If

Note that you can only create one level of subdirectory at a time. That's
why I don't have code to create the folder if C:\Folder1\Folder2 doesn't
exist.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Rocky said:
- Show quoted text -

Intersting concept!

Is it also possible to then create a new directory if the directory
does not exist?

If so, How do we dothis in code?

I save invoices to PDF and use the Acc No. as Directories.

Thanks

Rocky
 
Dim strFolder As String
Dim strSubfolder As String

  strFolder = "C:\Folder1\Folder2\"
  strSubfolder = "Subfolder"
  If Len(Dir(strFolder & strSubfolder, vbFolder)) > 0 Then
' C:\Folder1\Folder2\Subfolder exists
  Else
' C:\Folder1\Folder2\Subfolder doesn't exist.
' Make sure C:\Folder1\Folder2 exists...
    If Len(Dir(strFolder, vbFolder)) > 0 Then
' C:\Folder1\Folder2 exists: add the subfolder
      MkDir strFolder & strSubfolder
    Else
' C:\Folder1\Folder2 doesn't exist.
    End If
  End If

Note that you can only create one level of subdirectory at a time. That's
why I don't have code to create the folder if C:\Folder1\Folder2 doesn't
exist.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no private e-mails, please)




Intersting concept!

Is it also possible to then create a new directory if the directory
does not exist?

If so, How do we dothis in code?

I save invoices to PDF and use the Acc No. as Directories.

Thanks

Rocky

Thanks for the info. I will try it.

Rocky
 
Back
Top