dakarr
asked on
delete file after period of time
When supervisors are logged onto the system, a file exists in a directory:
If supervisor 248 is logged in, h:\kronos\data\supr248.001 exists.
The problem is users sometimes log on and forget to log off. I can bump them off by deleting their supervisor file, ie. del supr248.001
The file is always the same format supr###.001 if it is supervisor 10, the file is supr10.001.
I would like to set up an executable that deletes the file if it exists for more than 1 hour.
What would the code look like?
If supervisor 248 is logged in, h:\kronos\data\supr248.001
The problem is users sometimes log on and forget to log off. I can bump them off by deleting their supervisor file, ie. del supr248.001
The file is always the same format supr###.001 if it is supervisor 10, the file is supr10.001.
I would like to set up an executable that deletes the file if it exists for more than 1 hour.
What would the code look like?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Sub logoff(n As Integer)
Dim t
Dim sFile
'where n is your supervisor number
On Error GoTo bomb
n = 10
sFile = "supr" & Format(n, "000") & ".001"
t = CDate(FileDateTime(sFile))
If DateDiff("s", t, Now) > 3600 Then
Kill sFile
End If
bomb:
End Sub
Dim t
Dim sFile
'where n is your supervisor number
On Error GoTo bomb
n = 10
sFile = "supr" & Format(n, "000") & ".001"
t = CDate(FileDateTime(sFile))
If DateDiff("s", t, Now) > 3600 Then
Kill sFile
End If
bomb:
End Sub
In your case though, your path might need adding
Private Sub logoff(n As Integer)
Dim t
Dim sFile
'where n is your supervisor number
On Error GoTo bomb
n = 10
sFile = "h:\kronos\data\" & "supr" & Format(n, "000") & ".001"
t = CDate(FileDateTime(sFile))
If DateDiff("s", t, Now) > 60 Then
Kill sFile
End If
bomb:
End Sub
Private Sub logoff(n As Integer)
Dim t
Dim sFile
'where n is your supervisor number
On Error GoTo bomb
n = 10
sFile = "h:\kronos\data\" & "supr" & Format(n, "000") & ".001"
t = CDate(FileDateTime(sFile))
If DateDiff("s", t, Now) > 60 Then
Kill sFile
End If
bomb:
End Sub
ASKER
The format is set at "000" but may actually be "0", "00", or "000". Will this be okay with that?
I was assuming 010 etc, so you need to use the following with format replaced with cstr
Private Sub logoff(n As Integer)
Dim t
Dim sFile
'where n is your supervisor number
On Error GoTo bomb
n = 10
'change required
sFile = "h:\kronos\data\" & "supr" & cstr(n) & ".001"
t = CDate(FileDateTime(sFile))
'delete if 3600 seconds older
If DateDiff("s", t, Now) > 3600 Then
Kill sFile
End If
bomb:
End Sub
Private Sub logoff(n As Integer)
Dim t
Dim sFile
'where n is your supervisor number
On Error GoTo bomb
n = 10
'change required
sFile = "h:\kronos\data\" & "supr" & cstr(n) & ".001"
t = CDate(FileDateTime(sFile))
'delete if 3600 seconds older
If DateDiff("s", t, Now) > 3600 Then
Kill sFile
End If
bomb:
End Sub
ASKER
Thanks!
ASKER