Solved

FileListBox Question

Posted on 2002-03-19
7
256 Views
Last Modified: 2010-05-02
Hi there,
I need help with a filelistbox and i hope there is a sample for me out there. I need to no how to find
the oldest file in the list.
--------------------------------------
I have a listbox with files like here.
Every filename is : Hmmss_D-mmm.bck

145320_18-mrt.bck
145637_18-mrt.bck
215825_17-mrt.bck
234226_17-mrt.bck
---------------------------------------
I no that the file "215825_17-mrt.bck" is the oldest but is there a VB code to find the oldest file.
I have a timer to kill the oldest so that is wy i need it.

Sorry my englesh is not so good but i try.

Thanks..
Patrick Visser..
0
Comment
Question by:pfjvisser
  • 4
  • 3
7 Comments
 
LVL 1

Expert Comment

by:Doodle
Comment Utility
the FileDateTime(path) function will return the date of the files. Check them all work and then delete the oldest using the kill command.

Or yu could used th file system object [Microsoft Scripting Runtime]

Hope this helps

0
 

Author Comment

by:pfjvisser
Comment Utility
Thanks, but do you have a sample code for me plz.
I appr. it.
0
 
LVL 1

Expert Comment

by:Doodle
Comment Utility
Dim iCounter as integer
Dim dMinDate as date
Dim iOldestFileIndex as integer

For iCounter = 0 to LstFiles.ListCount-1
   if datediff("s",dMinDate,FileDateTime(LstFiles.List(iCounter)) > 0 then
       dmindate = filedatetime(lstfiles.list(iCounter)
       iOldestFileIndex = iCoutner
   end if
next
kill lstfiles.list(icounter)

This is assuming you are using a listbox with the files full path in the list. Havent tested the code so there could be a few buggs, but im sure you can work them out.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:pfjvisser
Comment Utility
Whel i'm happy that you send the sample code doodle,
but i 'm using a file listbox. Can you send it with the coding of the file listbox plz..
0
 
LVL 1

Accepted Solution

by:
Doodle earned 70 total points
Comment Utility
Dim iCounter as integer
Dim dMinDate as date
Dim iOldestFileIndex as integer

For iCounter = 0 to File1.ListCount-1
  if datediff("s",dMinDate,FileDateTime(file1.path & "\" & File1.List(iCounter)) > 0 then
      dmindate = filedatetime(file1.path & "\" & File1.list(iCounter)
      iOldestFileIndex = iCoutner
  end if
next
kill file1.path & "\" File1.list(icounter)

0
 

Author Comment

by:pfjvisser
Comment Utility
Yha i did recoded it the same as you yesterday but thanks an. Whel here are your points so thaks for helping me out oke.
0
 

Author Comment

by:pfjvisser
Comment Utility
Yha i did recoded it the same as you yesterday but thanks an. Whel here are your points so thaks for helping me out oke
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

9 Experts available now in Live!

Get 1:1 Help Now