[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Search and kill the the file..

Hi there,
I’m in a bit of problems and I  have a filelistbox called file1.In that listbox are files called like down here.

---FILELISTBOX---
145320_18-mrt.bck
145637_18-mrt.bck
215825_17-mrt.bck = Formatted as Time 21:58:25 Date _17- march
234226_17-mrt.bck

I need to have a coding to select the oldest file that is (215825_17-mrt.bck) ad the moment and kill it. Do you no how to do this. I need the coding fast plz. Help..

Tanks.
0
pfjvisser
Asked:
pfjvisser
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Hope you understand this bit of code without explanations:

dim strFile as string
dim datNow as date
dim datOldest as Date
dim datFile as Date

datNow = now()
datOldest = datNow

strFile = dir("c:\yourfiles\*.bck")
while strFile <> empty
  datFile = DateSerial ( year (datnow), Month(datnow), mid( strFile, 8,2))+ TimeSerial ( mid ( strFile, 1,2 ), mid ( strFile, 3,2), mid ( strFile, 5,2 ) )
 
  if datFile < datOldest then
    datOldest = datFile
  end if
  strFile = dir()
wend

if datFile < datNow then
  strFile = "c:\yourfiles\" & Format ( datOldest, "hhnnss\_dd" & -mrt.bck"
  kill strFile
end if

CHeers
0
 
pfjvisserAuthor Commented:
Whel tanks angellll.
It worked out with a bit of recoding i had to do. There you points thanks again..
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now