Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

File System Object VBScript

vbscript class wrapper to expose file system object methods and properties.

CLASS FSOBJ
dim FSO, f, f1, fc, s
dim  nso
Sub Class_Initialize()
   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set nso = CreateObject("WScript.Network")
End Sub

Sub Class_Terminate()
   Set FSO = Nothing
   Set nso = Nothing
End Sub
Property Get GetFolder(folderspec) 
Set GetFolder = FSO.GetFolder(folderspec)
End Property
Property Get GetFile(filespec)
Set GetFile = FSO.GetFile(filespec)
End Property
Property Get GetFileSize(filespec) 

Set f = FSO.GetFile(filespec)
GetFileSize = f.Size
End Property
Property Get GetComputerName() 
 GetComputerName = nso.computername
End Property

Function FolderExists(folderspec)
   Set FSO = CreateObject("Scripting.FileSystemObject")
   FolderExists = FSO.FolderExists(folderspec)
End Function
Function FileExists(pathNfilespec)
    'folderspec = Left(pathNfilespec, Len(pathNfilespec) - InStrRev(pathNfilespec, "\") + 1)
    'filespec = Right(pathNfilespec, InStrRev(pathNfilespec, "\") - 1)
   Set FSO = CreateObject("Scripting.FileSystemObject")
   'FolderExists = fso.FolderExists(folderspec)
   FileExists = FSO.FileExists(pathNfilespec)
End Function
Function FileDelete(pathNfilespec)
    'folderspec = Left(pathNfilespec, Len(pathNfilespec) - InStrRev(pathNfilespec, "\") + 1)
    'filespec = Right(pathNfilespec, InStrRev(pathNfilespec, "\") - 1)
   Set FSO = CreateObject("Scripting.FileSystemObject")
   If FSO.FileExists(pathNfilespec) = True Then
   FSO.DeleteFile pathNfilespec, True
   End If
End Function
Function ShowFileAccessInfo(filespec)
  Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(folderspec) = True Then
    Set f = FSO.GetFile(filespec)
  s = f.path & "<br>"
  s = s & "Created: " & f.DateCreated & "<br>"
  s = s & "Last Accessed: " & f.DateLastAccessed & "<br>"
  s = s & "Last Modified: " & f.DateLastModified
  ShowFileAccessInfo = s
End If
End Function
Function FileModified(pathNfilespec)
    'folderspec = Left(pathNfilespec, Len(pathNfilespec) - InStrRev(pathNfilespec, "\") + 1)
    'filespec = Right(pathNfilespec, InStrRev(pathNfilespec, "\") - 1)
   Set FSO = CreateObject("Scripting.FileSystemObject")
     Set f = FSO.GetFile(pathNfilespec)
   If FSO.FileExists(pathNfilespec) = True Then
   FileModified = f.DateLastModified
   End If
End Function
Function FileAccessed(pathNfilespec)
    'folderspec = Left(pathNfilespec, Len(pathNfilespec) - InStrRev(pathNfilespec, "\") + 1)
    'filespec = Right(pathNfilespec, InStrRev(pathNfilespec, "\") - 1)
   Set FSO = CreateObject("Scripting.FileSystemObject")
     Set f = FSO.GetFile(pathNfilespec)
   If FSO.FileExists(pathNfilespec) = True Then
   FileAccessed = f.DateLastAccessed
   End If
End Function
Sub AddNewFolder(path, folderName)
Dim nf
   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set f = FSO.GetFolder(path)
   Set fc = f.SubFolders
   If folderName <> "" Then
      Set nf = fc.Add(folderName)
   Else
      Set nf = fc.Add("New Folder")
   End If
End Sub


Function ShowFileList(folderspec)

   Dim FSO, f, f1, fc, s

   Set FSO = CreateObject("Scripting.FileSystemObject")

   Set f = FSO.GetFolder(folderspec)

   Set fc = f.FILES

   For Each f1 In fc

      s = s & f1.Name

      s = s & vbTab

   Next

   ShowFileList = s

End Function
Sub FILES(FolderNPath)

   Dim FSO, f, f1, fc, s

   Set FSO = CreateObject("Scripting.FileSystemObject")

   Set f = FSO.GetFolder(FolderNPath)

   Set fc = f.FILES

   For Each f1 In fc
    
   Next
End Sub
Sub CopyFile(Source , Destination , Overwrite )
    
FSO.CopyFile Source, Destination, Overwrite
End Sub

END CLASS
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS