DateLastAccessed Problem

S

sb

I'm trying to come up with a simple script to iterate through a bunch of
images in a directory and delete the ones that haven't been viewed in x
number of months. I thought "DateLastAccessed" would be the way to go but
it seems to have a rather strict interpretation of what consists of "access"
If I view a file, has it not been "accessed"? Not according to my script.
No matter how many times I view an image, the value stays the same...

Can anyone point me in the right direction here?
 
R

Randy Rahbar

Can anyone point me in the right direction here?

You could have all your image path's pointing to an asp page, which then
records the image name and date in a database and then displays the image.

This example might get you started...
http://www.aspfaq.com/2276

-Randy
 
H

Horhayson

This is what I wrote (with some help from the users at
developersdex.com). It queries a directory, compiles a list that is x
number of days old, deletes the files, emails you a copy of the list of
files, and deletes the file list (using a couple of batch files that
could easily be worked in).

====================
Option Explicit

Dim oFS, sSourceDir, nDays, nTotal, sFileList

Set oFS = WScript.CreateObject("Scripting.FileSystemObject")

'set nDays to be the number of days since last accessed
'(6 months is 180 days)
nDays = 180

'Put your directory you want to query as the sSourceDir
'sSourceDir = "\\server\users\JohnDoe"

Call FindOldFiles(oFS.GetFolder(sSourceDir))

If nTotal > 1 Then

' MsgBox "WARNING: Time to archive files!" & vbCrlf & _
'
"------------------------------------------------------------------" &
vbCrlf & vbCrlf & _
' "You have " & nTotal & " file(s) that need to be archived!"
& vbCrlf & sFileList, vbInformation ,"Archive Check"

'------------------------------
' Write out results to log file


Dim FileSystemObject, TextStream

Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set TextStream = FileSystemObject.CreateTextFile("C:\oldfiles.LOG",
True)

TextStream.WriteLine ("This script has deleted " & nTotal & " file(s)
from some folder on some server") & vbCrlf & _
"--------------------------------------------------" & vbCrlf & _
sFileList ', vbInformation, "Archive Check"

TextStream.Close

'------------------------------
' Email results

Dim stdout, shell
Dim cmd
function ExecCmd(cmdline)
set stdout = wscript.stdout
set shell = createobject("wscript.shell")
set cmd = shell.exec(cmdline)
do until cmd.status = 1 : wscript.sleep 5 : loop
ExecCmd = cmd.stdout.readall
End Function

ExecCmd ("oldfile.bat")
'----------------------
'
' oldfile.bat
'
' blat c:\oldprofiles.log -s "Old Profiles that have
' not been accessed in 180 days on SomeServer"
' -t (e-mail address removed)
' del c:\oldprofiles.log
'
' -------------------------
Else
MsgBox "No files need to be archive", vbInformation ,"Archive Check"
End If

'

WSCript.Quit

'---------------------
Sub FindOldFiles(oFolder)
Dim oFile, oSubFolder

For Each oFile In oFolder.Files
If IsOlder(oFile, nDays) Then
nTotal = nTotal + 1
sFileList = sFileList & oFile.Path & vbCrlf
'--------
'
' Deletes old files
'
'--------
oFS.GetFile (oFile)
oFS.DeleteFile (oFile)
'--------
'
' Comment out the lines above if do not want to delete
'
'--------
End If
Next
For Each oSubFolder In oFolder.SubFolders
Call FindOldFiles(oSubFolder)
Next

End Sub

'---------------------
Function IsOlder(oFile, nDays)
IsOlder = False
If DateDiff("d", oFile.DateLastAccessed, Now) > nDays Then IsOlder =
True
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,104
Messages
2,570,646
Members
47,248
Latest member
Angelita78

Latest Threads

Top