And likewise, the
functions are used to retrieve information about a file, and the subroutines
are used to perform actions on a file. The arguments should all be fully qualified
filenames (e.g., C:\Windows\notepad.exe). You may want to use the
FileExists function before any others to prevent errors:
Sub FileCopy(Source, Destination)
Set FileObject = CreateObject("Scripting.FileSystemObject")
FileObject.CopyFile Source, Destination
End Sub
528 | Chapter 9: Scripting and Automation
Function FileDate(Filename)
Set FileObject = CreateObject("Scripting.FileSystemObject")
Set FileHandle = FileObject.GetFile(Filename)
GetFileDate = FileHandle.DateCreated
End Function
Sub FileDelete(Filename)
Set FileObject = CreateObject("Scripting.FileSystemObject")
FileObject.DeleteFile(Filename)
End Sub
Function FileExists(Filename)
Set FileObject = CreateObject("Scripting.FileSystemObject")
FileExists = FileObject.FileExists(Filename)
End Function
Function FileExtension(Filename)
Set FileObject = CreateObject("Scripting.FileSystemObject")
GetFileExtension = FileObject.GetExtensionName(Filename)
End Function
Sub FileMove(Source, Destination)
Set FileObject = CreateObject("Scripting.FileSystemObject")
FileObject.MoveFile Source, Destination
End Sub
Function FileSize(Filename)
Set FileObject = CreateObject("Scripting.FileSystemObject")
Set FileHandle = FileObject.GetFile(Filename)
FileSize = FileHandle.Size
End Function
This next two functions can be used on either files or folders and allow you
to retrieve and set file attributes (Archive, Read-Only, System, and Hidden),
respectively.
Pages:
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735