' ****************************************************** ' * ' * Copyright 2011 - www.craftydba.com ' * ' * Name: clsManageFiles ' * ' * Design Phase: ' * Author: John Miner ' * Date: 07/02/2008 ' * Purpose: A class to manage files. ' * ' ****************************************************** ' Define all variables Option Explicit ' ' Load the class library ' ExecuteGlobal CreateObject("Scripting.FileSystemObject").OpenTextFile(CurrentPath() & "mod-manage-files.vbs").ReadAll ' ' Get The Current Program Path ' Function CurrentPath() CurrentPath = Replace(WScript.ScriptFullName, WScript.ScriptName,"") End Function ' ' Code to test the program ' Public Function TestFileCode() ' Create the file object Dim objFiles Set objFiles = New clsManageFiles ' Set paths Dim strPath(2) strPath(1) = "C:\vbs-depot\fso\one\" strPath(2) = "C:\vbs-depot\fso\two\" ' Set full file name objFiles.SetFn strPath(1) & "presidents.csv" ' Get file, directory & access info Wscript.Echo "File Name = " & objFiles.GetFileName Wscript.Echo "Directory Name = " & objFiles.GetDirName Wscript.Echo "Size In Bytes = " & objFiles.GetFileSizeInBytes Wscript.Echo "Date Created = " & objFiles.GetDateCreated Wscript.Echo "Last Access = " & objFiles.GetLastAccess Wscript.Echo "Last Modified = " & objFiles.GetLastModified Wscript.Echo "Attributes = " & objFiles.GetFileAttributes ' Copy file to backup Wscript.Echo "Copy file0 in dir1 to file1 in dir2" objFiles.CopyFn strPath(2) & "backup1.csv" Wscript.Echo "Copy file0 in dir1 to file2 in dir2" objFiles.CopyFn strPath(2) & "backup2.csv" ' Copy to file stamp Wscript.Echo "Copy file0 in dir1 to file3 w/stamp in dir2" objFiles.CopyFn strPath(2) & "backup3-" & objFiles.MakeFileStamp() & ".csv" ' Set path objFiles.SetFn strPath(2) & "backup1.csv" ' Move the file Wscript.Echo "Copy file1 in dir2 to dir1" objFiles.MoveFn strPath(1) & "backup1.csv" ' Set path objFiles.SetFn strPath(1) & "presidents.csv" ' Make file read only, fails on next step Wscript.Echo "Set file0 to read only" objFiles.SetFileAttributes(3) ' Delete the file Wscript.Echo "Try to delete read only file0" objFiles.DeleteFn End Function ' -- Run the test -- TestFileCode