Python Forum
filter every 24 days file (considering file name)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
filter every 24 days file (considering file name)
#1
Hi
I have a folder that contains many eof extension files name I want to sort them in ordinary way with python code (as you can see in my example the name of all my files contain a date like:20190729_20190731 and they are just satellite orbital information files, then select and filtered 1th,24th,47th and.... (index ) of files and delete others because I need every 24 days information files( ex.V20190822T225942_20190824T005942) not all days information .for facility I select and chose these information files from first day I need so the first file is found then I should select 24 days after from first then 47 from first or 24 days after second file and so on. I exactly need to keep my desire files as I said and delete other files in my EOF source folder my desire files are like these

S1A_OPER_AUX_POEORB_OPOD_20190819T120911_V20190729T225942_20190731T005942.EOF
S1A_OPER_AUX_POEORB_OPOD_20190912T120638_V20190822T225942_20190824T005942.EOF
.
.
.
thank you
from importlib.metadata import files
import pprint

items = os.listdir("C:/Users/m/Desktop/EOF")

eof_files = []
for item in items:
  
    if item.lower().endswith('.eof'):
        eof_files.append(item)

eof_files.sort(key=lambda fname : fname.split('_')[6])
#keeping itemes
count=0
for eof_file in eof_files:
 if fname.split('_')[6]==fname.split('_')[6]+24

   print(f"Keeping: [eof_file]")
Reply


Messages In This Thread
filter every 24 days file (considering file name) - by RolanRoll - Mar-04-2022, 08:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  file open "file not found error" shanoger 8 1,187 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Need to replace a string with a file (HTML file) tester_V 1 790 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 956 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,132 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,151 Dec-15-2022, 04:32 PM
Last Post: Larz60+
Photo Making Zip file of a file and Directory Nasir 2 1,047 Oct-07-2022, 02:01 PM
Last Post: Nasir
  Need Help: Convert .pcl file to .pdf file ManuRaval 6 2,576 Sep-13-2022, 01:31 PM
Last Post: ManuRaval
  How split N days between specified start & end days SriRajesh 2 1,348 May-06-2022, 02:12 PM
Last Post: SriRajesh
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,725 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  How to split file by same values from column from imported CSV file? Paqqno 5 2,837 Mar-24-2022, 05:25 PM
Last Post: Paqqno

Forum Jump:

User Panel Messages

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