Solved

delete files older than 3 days of creation

Posted on 2011-03-08
9
324 Views
Last Modified: 2012-05-11
hi there,
I need to see use code on MS Access to delete files older than 3 days of creation base on date time created.
Whats the best solution for this task at hand?
Thanks,
COHFL
0
Comment
Question by:COHFL
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 84
Comment Utility
What do you mean by "files"? Are you referring to files stored on disc, or are you referring to records in an Access table?

0
 
LVL 3

Expert Comment

by:CarlsbergFTW
Comment Utility
Open the cmd window, go to the folder you want to delete the files from and execute the following command:
forfiles -d -7 -c "cmd /c dir @file"
-- or --
forfiles -d -7 -c "cmd /c dir @path"

This will show you the files you want to delete. To actually delete them, do this:
forfiles -d -7 -c "cmd /c del @file"

The -7 is exactly 7 24 hour periods. So if it is 5:00pm and you want to delete a file from 6:00pm 7 days ago, it won't find it. It will find files before 5:00pm 7 days ago.

I highly suggest lookin at the help also by using the command: forfiles /?

Once you get what you want, you can put it in your own bat file also.
0
 
LVL 2

Expert Comment

by:chris_smith_51
Comment Utility
Hi COHFL,

Sorry to be a pain, but do you mean to delete *records* in the database which are older than 3 days (files are something different!)?

...In which case a simple SQL DELETE query should do the trick:

DELETE FROM tbl_name WHERE creation_date < getdate()-3;

You can implement this in SQL Query Design View located through the wizard in Access.

Chris

0
 
LVL 3

Expert Comment

by:CarlsbergFTW
Comment Utility
"FILES" i guess, the good part is the he received solution(s)for both situations.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 84
Comment Utility
The author asked for CODE to do this, not commands to manage this by hand. While a batch file could be used, of course, your solution wouldn't really be Access-friendly.
0
 
LVL 3

Expert Comment

by:CarlsbergFTW
Comment Utility
I appreciate your remarks but i suppose we are both trying to help out this person. It's noone's fault that people do not provide the exact information that we need in order to help them correctly. Ss i said in my previous post, in this case it's better to have multiple answers that solve one problem than having multiple unanswered questions.

Have a sweet day.
0
 

Author Comment

by:COHFL
Comment Utility
I'm sorry for the confusion my question has cause. What im trying to do is to have a routine that went it gets call it goes out and the following:

Private Sub cmdDeleteFiles_Click()
On Error GoTo Err_cmdDeleteFiles_Click

Dim Directory as string
Directory = "C:Windows\Folder\"

'now here i need to loop for all the files that are and stored in Directory once i have them compared them with datetime() and the file datetime creation  and if the day is > than 3 them delete it. otherwise just leave it alone.


Exit_cmdDeleteFiles_Click:
    Exit Sub

Err_cmdDeleteFiles_Click:
    MsgBox Err.Description
    Resume Exit_cmdDeleteFiles_Click
End Sub

I have done this on .Net but MS Access does not behave the same way hence my question.
Help will be greatly appreciated.
0
 

Accepted Solution

by:
COHFL earned 0 total points
Comment Utility
perhaps this little function will do the job:
Function delete_old(ByVal Dir_Path As String) As String
Dim Masq_File As String
Dim File_Date As Integer
Dim FDate As Date

Dim MyMonth As String
Masq_File = Dir_Path & "\" & "*.*"
Dir_Result = Dir(Masq_File, vbNormal)
    While (Dir_Result <> "")
    On erro GoTo BadName
    FDate = FileDateTime(Dir_Path & "\" & Dir_Result)
        If (FDate < DateAdd("d", -5, Now())) Then
            Kill Dir_Path & "\" & Dir_Result
        End If
BadName:
    Dir_Result = Dir
    Wend
End Function
0
 

Author Closing Comment

by:COHFL
Comment Utility
it did what i really needed to do
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now