Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

FileListBox Question

Posted on 2002-03-19
7
282 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
ID: 6879408
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
ID: 6879479
Thanks, but do you have a sample code for me plz.
I appr. it.
0
 
LVL 1

Expert Comment

by:Doodle
ID: 6879508
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:pfjvisser
ID: 6879785
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
ID: 6882063
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
ID: 6882096
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
ID: 6882099
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

856 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