0

I have more than 1000 files in the same folder. I want to read selected files from it.

File names

Here randon_text is different in each file. I have successfully fetched all file names in one list name file_name_list.

I want something like below

file_name == part_0000 then Work1

file_name != _confirm or _start then work2

I have done some part of the required work using the below code. for i in file_name_list: if i.name == "part_0000"

Here I don't know how to read file with matching text or the same format in python. I need something the same as like function in SQL so I can read files with initial text only.

1
  • 2
    You probably want to use a regex or startswith() Commented Feb 20, 2020 at 8:31

1 Answer 1

1
for i in file_name_list: 
    if "part_0000" in i.name:
           if "part_00001" in i.name or "part_00002" in i.name:
               continue
           #enter your condition here....
Sign up to request clarification or add additional context in comments.

2 Comments

How to write not condition with your comment like if iI want to read all file except part_00001 and part_00002.
edited the code, using the conitinue it will skip the condition

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.