Professional Web Applications Themes

DateLastAccessed Problem - ASP

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?...

  1. #1

    Default DateLastAccessed Problem

    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?


    sb Guest

  2. #2

    Default Re: DateLastAccessed Problem

    > 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...
    [url]http://www.aspfaq.com/2276[/url]

    -Randy


    Randy Rahbar Guest

  3. #3

    Default Re: DateLastAccessed Problem



    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 [email]usernamesomedomain.com[/email]
    ' 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


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Horhayson Guest

Similar Threads

  1. contribute problem - access denied file may not existpermission problem
    By Al1973 in forum Macromedia Contribute Connection Administrtion
    Replies: 6
    Last Post: September 17th, 04:16 PM
  2. Replies: 2
    Last Post: September 30th, 12:13 PM
  3. DateLastAccessed
    By Horhayson in forum ASP
    Replies: 0
    Last Post: September 23rd, 02:42 PM
  4. Replies: 0
    Last Post: August 2nd, 03:03 PM
  5. Replies: 2
    Last Post: July 17th, 07:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139