Solved

FileListBox Question

Posted on 2002-03-19
7
294 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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: 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.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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