Select files based on text list of filenames(part of the name:date) with condition

Joined
May 4, 2022
Messages
2
Reaction score
0
I want to Select some files in folder based on text list (name of files ( part of name is date )) so i have two inputs one folder that contains (EOF )extension file that I want to select some of them and the .txt file that has name of related files (relation explained in image that I have attached)

.csv or .text file is like this:
S1A_IW_SLC__1SDV_20190826T022837_20190826T022904_028734_0340DD_654D-SLC
S1A_IW_SLC__1SDV_20190919T022838_20190919T022905_029084_034D09_0129-SLC
S1A_IW_SLC__1SDV_20191013T022839_20191013T022906_029434_03590E_A824-SLC
S1A_IW_SLC__1SDV_20191106T022839_20191106T022906_029784_036538_06CC-SLC
S1A_IW_SLC__1SDV_20191130T022838_20191130T022905_030134_037166_4019-SLC
S1A_IW_SLC__1SDV_20191224T022837_20191224T022904_030484_037D7B_0FC4-SLC
S1A_IW_SLC__1SDV_20210217T062720_20210217T062747_036626_044D90_4570-SLC
.
.
.
And Eof files in folder are like :
S1A_OPER_AUX_POEORB_OPOD_20190915T120743_V20190825T225942_20190827T005942.EOF
S1A_OPER_AUX_POEORB_OPOD_20190916T120658_V20190826T225942_20190828T005942.EOF
.
.
.
The result or selected eof files are like these:
S1A_OPER_AUX_POEORB_OPOD_20190915T120743_V20190825T225942_20190827T005942.EOF
S1A_OPER_AUX_POEORB_OPOD_20191009T120716_V20190918T225942_20190920T005942.EOF
. . .
SO

1-first: (in names.csv) extract part of file name(date) :find all("1SDV_(\d+)T", name)

2-second: (in name of files in specific folder) extract part of file name(date): find all ("_V(\d+)T", name) of all (EOF) extension file names in specific folder

3-third: relate extracted part: as image that I attached (red connected arrow)

4-select desire files after previous steps


Python:
import os
import re
# open the file, make a list of all filenames, close the file
with open('names.csv') as names_file:
# use .strip() to remove trailing whitespace and line breaks
   names= [line.strip() for line in names_file]
   for name in names:
    res = re.findall("__1SDV_(\d+)T", name)
   if not res: continue
   print res[0]
# You can append the result to a list
# Find all ("_V(\d+)T")
# how  can I relate (EOF) extension files name to res like image file I
attached   
 
 
# move the Eof file
os.rename(os.path.join('path', Eof file extention folder), '/path/to/somewhere/else')
break
 

Attachments

  • mm.png
    mm.png
    16.8 KB · Views: 21
  • mnm.png
    mnm.png
    4.4 KB · Views: 23

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,056
Messages
2,570,443
Members
47,089
Latest member
Bobby2025b

Latest Threads

Top