[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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?
0
dakarr
Asked:
dakarr
  • 4
  • 3
1 Solution
 
dakarrAuthor Commented:
The OS is WinNT if that makes any difference.
0
 
deightonCommented:
Dim t
Dim sFile
Dim n As Integer

'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:
   


0
 
deightonCommented:
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
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
deightonCommented:
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
0
 
dakarrAuthor Commented:
The format is set at "000" but may actually be "0", "00", or "000".  Will this be okay with that?
0
 
deightonCommented:
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
0
 
dakarrAuthor Commented:
Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now