[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script - Last File Accesssed

Posted on 2005-04-07
5
Medium Priority
?
237 Views
Last Modified: 2010-04-18
Hi all,

Does anybody know where I can find a batch/vb script that will print to a file all filenames & folders the were last accessed 6 months ago?

Want to run this on my file server where I've got tons of files that were used once and never again.

Thanks
Stevengreen
0
Comment
Question by:stevengreen
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 1000 total points
ID: 13728060
Hi stevengreen,

The following script should do the trick.  To use it do the following:
1.  Start Notepad
2.  Copy the script below and paste it into Notepad
3.  Edit the script as needed.  You'll need to change strBasePath to point to the root of the path you want the script to run against
4.  Save the Notepad file.  You may name it anything you want so long as the name ends with .vbs
5.  Run the script by issuing this command from either a command prompt or the run command dialog-box:
     cscript scriptname.vbs > outputfilename

'Script begins here
Option Explicit
Dim objFSO, intFolders, intFiles, strBasePath

Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set the path to the folder we'll start in
strBasePath = "C:\"
'Call the ProcessFolder subroutine and pass it the starting path
ProcessFolder strBasePath
'Clean up
Set objFSO = Nothing
Wscript.Echo ""
Wscript.Echo "Folders = " & intFolders & vbtab & "Files = " & intFiles
Wscript.Quit

Private Sub ProcessFolder(strFolderPath)
    Dim objFolder, objSubFolders
    'Create the starting folder object
    Set objFolder = objFSO.GetFolder(strFolderPath)
    'Call the ProcessFiles subroutine and pass it the folder object
    ProcessFiles objFolder
    intFolders = intFolders + 1
    'Create the sub-folders object
    Set objSubFolders = objFolder.SubFolders
    'Loop through the sub-folders in the folder object
    For Each objFolder In objSubFolders
        'Call the ProcessFiles subroutine and pass it the sub-folder object
        ProcessFolder objFolder.Path
        intFolders = intFolders + 1
    Next
    'Dispose of the created objects
    Set objSubFolders = Nothing
    Set objFolder = Nothing
End Sub

Private Sub ProcessFiles(objFolder)
    Dim objFile
    'Loop through the files in the folder object
    For Each objFile In objFolder.Files
        If Datediff("m", objFile.DateLastAccessed, date()) >= 1 Then
            Wscript.Echo objFile.Path
            intFiles = intFiles + 1
        End If
    Next
    'Dispose of the object created in this subroutine
    Set objFile = Nothing
End Sub
'Script ends here

Cheers!
0
 
LVL 3

Author Comment

by:stevengreen
ID: 13733735
Ok,

This looks awesome.  Is there a way that I can get it to print the date next to each filename as well?

Also, if I say wanted to change it from 6 months to 1 year how would I go about doing that?

Thank you for your help....
0
 
LVL 76

Expert Comment

by:David Lee
ID: 13735498
Sure.  To show the date change this line

    Wscript.Echo objFile.Path

to

    Wscript.Echo objFile.Path & " " & objFile.DateLastAccessed

To change from 6 months to 1 year, change the 6 to a 12.

No problem.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question