Python Forum
How to create def for sorted() from list of versioning files (filename+datetime)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create def for sorted() from list of versioning files (filename+datetime)
#3
(Jan-11-2017, 06:09 PM)snippsat Wrote: Here are some hints.
You can probably use getmtime(path),
Return the time of last modification of path/file.
Thank you for your effort, but as I already wrote (I know I wrote large text, hard to follow):
Quote:Just deleting anything older then (current date - x days) is not viable because if some file has not changed in that time, all versions (but current backup) will be deleted.
Versioning files appear only if there was a change. If last change of certain file was a year ago, then deleting anything older then a month would also delete every single versioning file, leaving only same file as user/client has on his PC.

So to keep at least one versioning file, it is imperative to parse the text and pull out:
1. original filename
2. date and time from the name itself

Which answers I need, as far as I understand:
a) I need to sort the list of files based on original name and date time (string operations), newer first
b) Outside of the sorted() I need to scroll through sorted list and using same string tools from a) and leave/skip only first two for each original file, deleting the rest.
c) Can someone provide me at least with proper format of "def" definition (with return?) so I can use it as a base? I understood that I need to use "key" function. This is the hardest part to understand.
Reply


Messages In This Thread
RE: How to create def for sorted() from list of versioning files (filename+datetime) - by DrLove73 - Jan-12-2017, 06:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete strings from a list to create a new only number list Dvdscot 8 1,608 May-01-2023, 09:06 PM
Last Post: deanhystad
  list the files using query in python arjunaram 0 698 Mar-28-2023, 02:39 PM
Last Post: arjunaram
  Create new folders and copy files cocobolli 3 1,537 Mar-22-2023, 10:23 AM
Last Post: Gribouillis
  Failing to print sorted files tester_V 4 1,324 Nov-12-2022, 06:49 PM
Last Post: tester_V
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,603 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  How to download a list of files from FTP? schnarkle 0 1,034 Jun-21-2022, 10:35 PM
Last Post: schnarkle
  Rename part of filename in multiple files atomxkai 7 7,464 Feb-18-2022, 10:03 PM
Last Post: atomxkai
  Python code to read second line from CSV files and create a master CSV file sh1704 1 2,444 Feb-13-2022, 07:13 PM
Last Post: menator01
  Append files and add column with last part of each filename NiKirk 0 2,657 Feb-04-2022, 07:35 AM
Last Post: NiKirk
  set and sorted, not working how expected! wtr 2 1,311 Jan-07-2022, 04:53 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020