|
-
Oct 19th, 2000, 04:08 PM
#1
Thread Starter
Member
Is there any code to use in a VB app that can search
files by date? And display files accessed in the past 5 days?
Thanks,
-
Oct 21st, 2000, 11:41 AM
#2
Junior Member
use this code to delete the old files from ur pc
Code:
Dim MyFile, MyStamp, DestDrive, DestPath
MyFile = Dir(DestDrive + DestPath + "\*.txt")'Change Extension
Do
MyStamp = FileDateTime(DestDrive + DestPath + "\" + MyFile) MyStamp = DateValue(Left$(MyStamp, 10))
If MyStamp < PurgeResp Then Kill(DestDrive + DestPath + "\" + MyFile)
MyFile = Dir
If MyFile = "" Then Exit Do
Loop
MsgBox "Selected files purged.", vbOKOnly, "Purge Files"
of course u must remove the kill statement & put ur code
-
Feb 8th, 2001, 01:23 PM
#3
New Member
Search Files By Date
Did you come up with a solution for returning a list of files that were last updated in a specified date range? I am looking to do the same thing and would like to know if there are API's that could retrieve this information
-
Feb 8th, 2001, 06:34 PM
#4
_______
<?>
Code:
'********************** bas module code
'for this example you need 1 listbox List1 and 1 command button Command1
'Get files in folder as per a date you supply
Option Explicit
Public myFileList()
Public Type FileInfoType
FileName As String
FileDate As Date
End Type
Public Function GetRecentFileList(ByVal Path As String, sDays As Integer) As FileInfoType()
Dim sList() As FileInfoType
Dim CurFile As String
Dim CurFileDate As Date
Dim IdxFile As Integer
Dim sNow As Date
'if the path is missing a \ then add it to the path
If Right(Path, 1) <> "\" Then Path = Path & "\"
'get the current file
CurFile = Dir(Path & "*.*")
'loop
Do While CurFile <> ""
CurFileDate = FileDateTime(Path & CurFile) 'file date
sNow = Now 'today's date
If DateDiff("d", CurFileDate, sNow) <= sDays Then
ReDim Preserve sList(IdxFile) As FileInfoType 'based on filecount of items in criteria
With sList(IdxFile) 'gather the date and time information
.FileName = CurFile
.FileDate = CurFileDate
End With
' Form1.List1.AddItem CurFile & sList(IdxFile).FileDate & _
" FileTime: " & sList(IdxFile).Filetime
ReDim Preserve myFileList(IdxFile) 'store the files and dates and times in an array
myFileList(IdxFile) = "File Name: " & sList(IdxFile).FileName _
& " FileTime: " & sList(IdxFile).FileDate
IdxFile = IdxFile + 1 'increment the counter
End If
CurFile = Dir() 'next file
Loop
GetRecentFileList = sList()
End Function
'********************** Form Code
'change C:\my documents for your directory
'change 5 to reflect the number of days you need
Option Explicit
Private Sub Command1_Click()
'declare an array of FileInfoType to hold the filelisting
Dim sFileList() As FileInfoType, x As Integer
sFileList = GetRecentFileList("c:\my documents", 5) 'get files from last 5 days
For x = LBound(myFileList) To UBound(myFileList)
List1.AddItem myFileList(x)
Next x
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|