Verifying a file exists

paulig2001

Registered User.
Local time
Today, 09:01
Joined
Apr 12, 2005
Messages
13
VB useses the FileExists funcion as follows:

object.FileExists(filespec)

Which returns true or faulse and where filespec is the file name and object is the name of a FileSystemObject.

What I need to know is what exactly a FileSystemObject is and if anyone could possibly give an example piece of code working?
 
This is a procedure I use to rename a file (that works).
It checks to see if it exist and then deletes it before renaming if it does.
Code:
Sub RenameFile(PTH As String, FN1 As String, FN2 As String)
Dim fso, f, P1
Set fso = CreateObject("Scripting.FileSystemObject")
If Right(PTH, 1) <> "\" Then
  P1 = PTH & "\"
Else
  P1 = PTH
End If
' Check if file exists (to rename to)
If fso.FileExists(P1 & FN2) Then
  ' Delete if not read only
  fso.DeleteFile P1 & FN2, False
End If
Set f = fso.GetFile(P1 & FN1)
f.Name = FN2
Set f = Nothing
Set fso = Nothing
End Sub
 
What I need to know is what exactly a FileSystemObject is and if anyone could possibly give an example piece of code working?
Seek and ye shall learn. :D

FileSystemObject Object
 

Users who are viewing this thread

Back
Top Bottom