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-2 of 2 total  RSS 

Simple FSO directory file listing

// simple browsing tool

<%

dim aryURL, URLvar
aryURL = Split(Request.ServerVariables("SCRIPT_NAME"), "/", -1, 1)
URLvar = aryURL(ubound(aryURL))

if request.querystring("sPP")<>"" then 
	
	sPP=request.querystring("sPP") & "\"
	ParentVar="<a href=""#"" onClick=""history.go(-1)"">Parent Directory</a><br><br>" & vbCrLF
else
	sPP = "\\serverlocation\"
end if

	
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set f = fso.GetFolder(sPP)  
	Set fc = f.Files 
	Set ff = f.SubFolders 
	For Each f1 in ff	
	  HeaderVar=HeaderVar& "<a href=""" & URLvar & "?sPP=" & sPP & f1.name & """>" & f1.name & "</a> &nbsp;|&nbsp;" & vbCrLF
	Next  
	For Each f1 in fc
	  SubHeaderVar=SubHeaderVar& "<a href=""" & sPP & f1.name & """>" & f1.name & "</a> <br>" & vbCrLF
	Next  
	Set ff = nothing
	Set fso = nothing
	Set f = nothing
	Set fc = nothing


response.write ParentVar
if HeaderVar<>"" then response.write "<b>Folders" & vbCrLF & "<br><br>&nbsp;|&nbsp;" & vbCrLF & HeaderVar & "</b><br><br>" & vbCrLF
if SubHeaderVar<>"" then response.write "<b>Files</b>" & vbCrLF & "<br><br>" & vbCrLF & SubHeaderVar & vbCrLF

%>




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-2 of 2 total  RSS