![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| | |||||||
| | Vista - folderLastAccessed script |
| |
| 11-17-2008 | #1 |
| | folderLastAccessed script 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? |
| My System Specs |
| 11-17-2008 | #2 |
| | Re: folderLastAccessed script <dkaloustian@xxxxxx> wrote in message news:e99ad288-c060-4aef-8cd0-a017729d4078@xxxxxx Quote: >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? Subfolders? Permissions? You need to be just a little more specific! |
| My System Specs |
| 11-17-2008 | #3 |
| | Re: folderLastAccessed script On Nov 17, 2:14*pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote: Quote: > <dkaloust...@xxxxxx> wrote in message > > news:e99ad288-c060-4aef-8cd0-a017729d4078@xxxxxx > Quote: > >I would like to run a vbscript on a mapped network drive via the > > letter is is mapped to, for example S: or H: Quote: > > Basically if I have a mapped network drive to S: (pretty much > > irrelevant) Quote: > > I would like to return the information for Quote: > > S:\Folder1 > > S:\Folder2 > > S:\Folder3 > > ....etc Quote: > > 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 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, objSheet, 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 worksheet objSheet.Name = "File Shares" ' Naming worksheet ' Populate spreadsheet cells with information objSheet.Cells (1, 1).Value = "Folder" objSheet.Cells (1, 2).Value = "Date Last Accessed" objSheet.Cells (2, 1).Value = strFolderProd objSheet.Cells (2, 2).Value = folderLastAccessed objExcel.Columns(1).ColumnWidth = 50 objExcel.Columns(2).ColumnWidth = 50 objExcel.ActiveWorkbook.SaveAs strExcelPath ' Saves excel spreadsheet 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" |
| My System Specs |
| 11-17-2008 | #4 |
| | Re: folderLastAccessed script 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@xxxxxx> wrote in message news:1f6c9848-3b5e-4053-a674-c23f17d12d03@xxxxxx On Nov 17, 2:14 pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote: Quote: > <dkaloust...@xxxxxx> wrote in message > > news:e99ad288-c060-4aef-8cd0-a017729d4078@xxxxxx > Quote: > >I would like to run a vbscript on a mapped network drive via the > > letter is is mapped to, for example S: or H: Quote: > > Basically if I have a mapped network drive to S: (pretty much > > irrelevant) Quote: > > I would like to return the information for Quote: > > S:\Folder1 > > S:\Folder2 > > S:\Folder3 > > ....etc Quote: > > 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 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, objSheet, 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 worksheet objSheet.Name = "File Shares" ' Naming worksheet ' Populate spreadsheet cells with information objSheet.Cells (1, 1).Value = "Folder" objSheet.Cells (1, 2).Value = "Date Last Accessed" objSheet.Cells (2, 1).Value = strFolderProd objSheet.Cells (2, 2).Value = folderLastAccessed objExcel.Columns(1).ColumnWidth = 50 objExcel.Columns(2).ColumnWidth = 50 objExcel.ActiveWorkbook.SaveAs strExcelPath ' Saves excel spreadsheet 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" |
| My System Specs |
![]() |
| Thread Tools | |
| |
| Similar Threads for: folderLastAccessed script | ||||
| Thread | Forum | |||
| Logon Script Causing Laptops To Hang - Problems in script? | VB Script | |||
| folderLastAccessed script (Access is denied) | VB Script | |||
| problem passing args to script 'There is no script engine for file extenstion' | VB Script | |||
| Include another script, keep variables in included script? | PowerShell | |||
| Script file has 'OS Handle' error when run from script | PowerShell | |||