Solved

FileListBox Question

Posted on 2002-03-19
7
288 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using Access 8 85
How to set the sa password in a vb6 code for sql connection 9 63
using web browser with BING 40 136
MsgBox 4 71
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

726 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