Re: folderLastAccessed script
- From: "Pegasus \(MVP\)" <I.can@xxxxxxxxxx>
- Date: Mon, 17 Nov 2008 23:59:49 +0100
Here is your loop. It will consider nothing other than the subfolders of
strFolder:
Set fs = CreateObject("Scripting.FileSystemObject")
strFolder = "H:\Oncall Schedule\"
For Each oFolder In fs.GetFolder(strFolder).SubFolders
s = UCase(strFolder & oFolder.Name) & VbCrLf _
& "Created: " & oFolder.DateCreated & VbCrLf _
& "Last Accessed: " & oFolder.DateLastAccessed & VbCrLf _
& "Last Modified: " & oFolder.DateLastModified
WScript.Echo s
Next
Note also:
- Since you never use the WshShell object, you might as well remove it from
your code.
- There is no point in creating two separate File System Objects (fs,
oFileSys). One will do perfectly well and can be reused any number of times.
- While it does not matter from an execution point of view, the readability
of your code would be enhanced if you modified your current structure from
this:
Main code
Some subroutine/function
More main code
More subroutines
Endo of Main Code
to this:
Main Code
End of Main Code
Subroutine/function1
Subroutine/function2
Subroutine/function3
It makes the code highly modular and much easier to maintain.
<dkaloustian@xxxxxxxxx> wrote in message
news:1f6c9848-3b5e-4053-a674-c23f17d12d03@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Nov 17, 2:14 pm, "Pegasus \(MVP\)" <I....@xxxxxxxxxx> wrote:
<dkaloust...@xxxxxxxxx> wrote in message
news:e99ad288-c060-4aef-8cd0-a017729d4078@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I would like to run a vbscript on a mapped network drive via the
letter is is mapped to, for example S: or H:
Basically if I have a mapped network drive to S: (pretty much
irrelevant)
I would like to return the information for
S:\Folder1
S:\Folder2
S:\Folder3
....etc
Anyone have any ideas?
What sort of information are you after? Number of files? File sizes?
Subfolders? Permissions? You need to be just a little more specific!
I would like to get the last time all the folders were last accessed.
I have put together this script that will return the information that
I want. It works partially but I need to encorporate some kind of
loop into it. I just want the time the root folders (S:\Folder1, S:
\Folder2, etc) were accessed. I don't want it to go all the way down
some of these folder structures because some of them are huge. This
is what I got so far. Thanks for your input.
Option Explicit
Dim WshShell
Dim fs, f, s, strfolder
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
strFolder = "H:\Oncall Schedule"
Set f = fs.GetFolder(strFolder)
s = UCase(strFolder) & vbCrLf
s = s & "Created: " & f.DateCreated & vbCrLf
s = s & "Last Accessed: " & f.DateLastAccessed & vbCrLf
s = s & "Last Modified: " & f.DateLastModified
CreateTextFile strFolder
Sub CreateTextFile(strFolderProd)
'Dim strFolderProd
Dim oFilesys, oFiletxt, sFilename, sPath, s, folderLastAccessed,
subfolders, objExcel, obj***, strExcelPath
'Dim strExcelPath = "C:\Documents and Settings\dkaloust\Desktop\New
Folder\TestFolderScript.xls"
Set oFilesys = WScript.CreateObject("Scripting.FileSystemObject")
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(strFolderProd)
'Set subfolders = f.SubFolders
'For Each f In subfolders
'Wscript.Echo f.DateLastAccessed
folderLastAccessed = UCase(strFolderProd) & vbCrLf
folderLastAccessed = f.DateLastAccessed
strExcelPath = "C:\Documents and Settings\dkaloust\Desktop\New Folder
\TestFolderScript.xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add ' Create a new workbook
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1) ' Bind to
work***
obj***.Name = "File Shares" ' Naming work***
' Populate spread*** cells with information
obj***.Cells (1, 1).Value = "Folder"
obj***.Cells (1, 2).Value = "Date Last Accessed"
obj***.Cells (2, 1).Value = strFolderProd
obj***.Cells (2, 2).Value = folderLastAccessed
objExcel.Columns(1).ColumnWidth = 50
objExcel.Columns(2).ColumnWidth = 50
objExcel.ActiveWorkbook.SaveAs strExcelPath ' Saves excel spread***
objExcel.ActiveWorkbook.Close ' Closes workbook
objExcel.Application.Quit 'Quits the excel application
Set oFiletxt = fs.CreateTextFile("C:\Documents and Settings\dkaloust
\Desktop\New Folder\TestFolderScript.txt",True)
sPath = fs.GetAbsolutePathName("C:\Documents and Settings\dkaloust
\Desktop\New Folder\TestFolderScript.txt")
sFilename = fs.GetFileName(sPath)
oFiletxt.WriteLine("Folder" & " " & "Last accessed on")
oFiletxt.WriteLine()
oFiletxt.WriteLine(f & " " & folderLastAccessed)
oFiletxt.Close
End Sub
WScript.Echo "Done"
.
- References:
- folderLastAccessed script
- From: dkaloustian
- Re: folderLastAccessed script
- From: Pegasus \(MVP\)
- Re: folderLastAccessed script
- From: dkaloustian
- folderLastAccessed script
- Prev by Date: Re: folderLastAccessed script
- Next by Date: Access to the specified device, path, or file is denied
- Previous by thread: Re: folderLastAccessed script
- Next by thread: Access to the specified device, path, or file is denied
- Index(es):