Solved

Last accessed folder information

Posted on 2013-11-28
7
315 Views
Last Modified: 2013-12-04
How to get the last access  files greater than 1 year along with size of files.
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 40

Expert Comment

by:footech
ID: 39684157
The following will get files that were last accessed more than a year ago.  Size is returned by default, so no need to do anything special.
$startfolder = "c:\whatever"
$age = (Get-Date).AddYears(-1)
Get-ChildItem $startfolder -Recurse | Where {$_.LastAccessTime -lt $age}

Open in new window

0
 
LVL 5

Author Comment

by:VIVEKANANDHAN_PERIASAMY
ID: 39684187
Output gives like below:
  Directory: E:\Software\SQL2008\x64\setup\sql_engine_core_inst_msi\pfiles\sqlservr\mssql.x\mssql\binn\dlltmp32


Mode                LastWriteTime     Length Name                                                                                                                                      
----                -------------     ------ ----                                                                                                                                      
-a---          4/3/2010   7:21 AM      73568 dws5mxvv.dll                                                                                                                              
-a---          4/3/2010   7:21 AM      47456 lo7viuxq.dll                                                                                                                              


    Directory: E:\Software\SQL2008\x64\setup\sql_engine_core_inst_msi\pfiles\sqlservr\mssql.x\mssql\binn\dlltmp64


Mode                LastWriteTime     Length Name                                                                                                                                      
----                -------------     ------ ----                                                                                                                                      
-a---          4/3/2010   6:27 AM      79200 4a0g_qam.dll                                                                                                                              
-a---          4/3/2010   6:27 AM      77152 a34tgahi.dll                                                                                                                              


    Directory: E:\Software\SQL2008\x64\setup\sql_engine_core_inst_msi\pfiles\sqlservr\mssql.x\mssql\binn\template


Mode                LastWriteTime     Length Name                                                                                                                                      
----                -------------     ------ ----                                                                                                                                      
-a---          4/2/2010   1:11 PM    4194304 master.mdf                                                                                                                                
-a---          4/2/2010   1:11 PM     524288 mastlog.ldf                                                                                                                              
-a---          4/2/2010   1:11 PM    1310720 model.mdf                                                                                                                                
-a---          4/2/2010   1:11 PM     524288 modellog.ldf                                                                                                                              
-a---          4/2/2010   1:11 PM   11534336 msdbdata.mdf                                                                                                                              
-a---          4/2/2010   1:11 PM     524288 msdblog.ldf  


instead i like have full pathname and size in kb and last accessed time not lastwritetime
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39684434
You just need to use Select-Object cmdlet to get the required properties..
Try..
Get-ChildItem "E:\Files" -Recurse | 
  Where {$_.LastAccessTime -lt (Get-Date).AddYears(-1) -and !($_.PSIsContainer) } |
  Select FullName,LastAccessTime,@{N="Size KB";E={"{0:N2}" -f ($_.Length /1KB)}} |
Export-Csv C:\report.csv -nti

Open in new window

0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39684531
Not sure if you were interested in VBS, but since this question is tagged in that zone, here's an idea of what you can do there.  I typically like to send the output of scans like this to a CSV and then load in to Excel for sorting, formatting, printing, etc.  So, save the following as a VBS, and then run it passing it the starting folder for the output.  Redirect the output to a CSV file, and then open in Excel.

cscript //nologo EE28306189.vbs c:\yourfolder > report.csv

' Define needed filesystem object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

' Get folder name to list off the command line, make sure it's valid
If (WScript.Arguments.Count > 0) Then
    strFolder = Wscript.Arguments(0)
    If Right(strFolder, 1) = "\" Then strFolder = Left(strFolder, Len(strFolder)-1)
    If Not objFSO.FolderExists(strFolder & "\") Then
        WScript.Echo "Specified folder does not exist."
        WScript.Quit
    End If
Else
    WScript.Echo "No folder name specified to list."
    WScript.Quit
End If

' Header row
Wscript.Echo Quote("Path") & "," & Quote("Size") & "," & Quote("Accessed")

' Call recursive routine to list old files
ListFiles objFSO.GetFolder(strFolder)


' Recursively list files older than number of days specified
Sub ListFiles(objFolder)
    ' List any files older than specified time from this folder
    For Each objFile In objFolder.Files
        If DateDiff("y", objFile.DateLastAccessed, Now) > 0 Then 
            Wscript.Echo Quote(objFile.Path) & "," & objFile.Size/1024 & "," & Quote(objFile.DateLastAccessed)
        End If
    Next

    ' List all older files in any subfolders of this one
    For Each objSubFolder In objFolder.Subfolders
        ListFiles objSubFolder
    Next
End Sub

' Add surrounding double quotes to a string
Function Quote(s)
   Quote = Chr(34) & s & Chr(34)
End Function

Open in new window

~bp
0
 
LVL 5

Author Comment

by:VIVEKANANDHAN_PERIASAMY
ID: 39685225
The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 char
 i'm getting error like above.
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 39685352
Who's solution were you replying to?

Long filenames are a problem typically in any scripting language, and at best you're probably only going to be able to skip over those.

~bp
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39689750
To deal with the character limitation you may use robocopy. But with robocopy you cannot use the property. You can refer the following link to find a sample function which use robocopy. In the code you need replace /MaxAge and /MinAge with /MAXLAD and /MINLAD to use LastAccessTime instead of LastWriteTime.

http://gallery.technet.microsoft.com/scriptcenter/Get-Deeply-Nested-Files-a2148fd7
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
A procedure for exporting installed hotfix details of remote computers using powershell
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

756 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