Python Forum
select Eof extension files based on text list of filenames with if condition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
select Eof extension files based on text list of filenames with if condition
#1
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

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

Attached Files

Thumbnail(s)
       
Reply
#2
Please fix indentation.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Next/Prev file without loading all filenames WilliamKappler 9 458 Apr-12-2024, 05:13 AM
Last Post: Pedroski55
  Copy Paste excel files based on the first letters of the file name Viento 2 422 Feb-07-2024, 12:24 PM
Last Post: Viento
  unable to remove all elements from list based on a condition sg_python 3 424 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Move Files based on partial Match mohamedsalih12 2 808 Sep-20-2023, 07:38 PM
Last Post: snippsat
  Color a table cell based on specific text Creepy 11 1,959 Jul-27-2023, 02:48 PM
Last Post: deanhystad
  Making a question answering chatbot based on the files I upload into python. Joejones 1 1,215 May-19-2023, 03:09 PM
Last Post: deanhystad
  list the files using query in python arjunaram 0 669 Mar-28-2023, 02:39 PM
Last Post: arjunaram
  Sent email based on if condition stewietopg 1 856 Mar-15-2023, 08:54 AM
Last Post: menator01
  Very simple question about filenames and backslashes! garynewport 4 1,926 Jan-17-2023, 05:02 AM
Last Post: deanhystad
  azure TTS from text files to mp3s mutantGOD 2 1,695 Jan-17-2023, 03:20 AM
Last Post: mutantGOD

Forum Jump:

User Panel Messages

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