' ****************************************************** ' * ' * Name: clsManageFiles ' * ' * Design Phase: ' * Author: John Miner ' * Date: 07/02/2008 ' * Purpose: A class to manage files. ' * ' ****************************************************** ' Define all variables Option Explicit ' ' Define the class to manage files ' Class clsManageFiles ' Define the file name Private strSrcPath ' ' Define constructor method ' Public Sub SetFn(strFile) strSrcPath = strFile End Sub ' ' Copy src file to dst ' Function CopyFn(strDstPath) ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Destination already exists If (objFso.FileExists(strDstPath)) Then Exit Function End If ' Copy data On Error Resume Next objFso.CopyFile strSrcPath, strDstPath ' Release the object Set objFso = nothing End Function ' ' Move src file to dst ' Function MoveFn(strDstPath) ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Destination already exists If (objFso.FileExists(strDstPath)) Then Exit Function End If ' Move data On Error Resume Next objFso.MoveFile strSrcPath, strDstPath ' Rename file pointer strSrcPath = strDstPath ' Release the object Set objFso = nothing End Function ' ' Delete the src file ' Function DeleteFn() ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Destination already exists If (Not objFso.FileExists(strSrcPath)) Then Exit Function End If ' Delete data On Error Resume Next objFso.DeleteFile strSrcPath ' Release the object Set objFso = nothing End Function ' ' File does exist ' Function ExistFn() ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Data exists On Error Resume Next ExistFn = objFso.FileExists(strSrcPath) ' Release the object Set objFso = nothing End Function ' ' Get file name part ' Function GetFileName() ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Return the file name GetFileName = objFso.GetFileName(strSrcPath) ' Release the object Set objFso = nothing End Function ' ' Get dir name part ' Function GetDirName() ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Return the dir name GetDirName = objFso.GetParentFolderName(strSrcPath) ' Release the object Set objFso = nothing End Function ' ' Get the last time accessed ' Function GetLastAccess() ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Return last time GetLastAccess = objFso.GetFile(strSrcPath).DateLastAccessed ' Release the object Set objFso = nothing End Function ' ' Get the creation date ' Function GetDateCreated() ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Return create time GetDateCreated = objFso.GetFile(strSrcPath).DateCreated ' Release the object Set objFso = nothing End Function ' ' Get the creation date ' Function GetLastModified() ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Return modified time GetLastModified = objFso.GetFile(strSrcPath).DateLastModified ' Release the object Set objFso = nothing End Function ' ' Get the file size ' Function GetFileSizeInBytes() ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Return file size GetFileSizeInBytes = objFso.GetFile(strSrcPath).Size ' Release the object Set objFso = nothing End Function ' ' Get the file attributes ' Function GetFileAttributes() ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Get file attributes GetFileAttributes = objFso.GetFile(strSrcPath).Attributes ' Release the object Set objFso = nothing End Function ' ' Get the file attributes ' Function SetFileAttributes(strMask) ' Declare file system variables Dim objFso Set objFso = CreateObject("Scripting.FileSystemObject") ' Set file attributes objFso.GetFile(strSrcPath).Attributes = strMask ' Release the object Set objFso = nothing End Function ' ' Attribute mask bits ' ' 0 = Normal file ' 1 = Read-only file ' 2 = Hidden file ' 4 = System file ' 8 = Disk drive volume label ' 16 = Folder or directory ' 32 = Archive bit ' 1024 = Alias ' 2048 = Compressed file ' ' Make file stamp ' Function MakeFileStamp() ' Get current date Dim Date1 Date1=Now() ' Make up return string Dim strStamp strStamp = "" ' Month strStamp = strStamp & Right("00" & DatePart("m", Date1), 2) ' Day strStamp = strStamp & Right("00" & DatePart("d", Date1), 2) ' Year strStamp = strStamp & Right("00" & DatePart("yyyy", Date1), 2) ' Divider strStamp = strStamp & "-" ' Hour strStamp = strStamp & Right("00" & DatePart("h", Date1), 2) ' Minute strStamp = strStamp & Right("00" & DatePart("m", Date1), 2) ' Second strStamp = strStamp & Right("00" & DatePart("s", Date1), 2) ' Return the value MakeFileStamp = strStamp End Function End Class