Click here to Skip to main content
15,891,925 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
For example:
If the folder contains these files:
log_20160801.bak
log_20160802.bak
log_20160803.bak
log_20160804.bak
log_20160805.bak
log_20160806.bak

How to reads the last modified date of the files and sorts them and deletes the older files:
log_20160806.bak


What I have tried:

I have tried to get every backup files creat-time ,and than compare ,choose the min-value ,delete the relate backup file. But I feel it's too hard to me, because I'm learn C++ recently.
I hope to get help for you. Thank you. With my best wish!
Posted
Updated 9-Aug-16 5:20am

Maybe look here[^] for file times.
and here[^] for file deletions.
 
Share this answer
 
Try this way:
C++
// Load an array with the list of file names log*.bak

// sort the array in descending order

// delete all files with name after fifth position in array
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900