Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:30:06+00:00 2026-06-05T17:30:06+00:00

I am trying to find a sub-string in a string, but I am not

  • 0

I am trying to find a sub-string in a string, but I am not achieving the results I want.

I have several strings that contains the direction to different directories:

'/Users/mymac/Desktop/test_python/result_files_Sample_8_11/logs', 
'/Users/mymac/Desktop/test_python/result_files_Sample_8_1/logs', 
'/Users/mymac/Desktop/test_python/result_files_Sample_8_9/logs'

Here is the part of my code here I am trying to find the exact match to the sub-string:

 for name in sample_names:

        if (dire.find(name)!=-1): 

            for files in os.walk(dire):

                for file in files:
                    list_files=[]
                    list_files.append(file)
                    file_dict[name]=list_files

Everything works fine except that when it looks for Sample_8_1 in the string that contains the directory, the if condition also accepts the name Sample_8_11. How can I make it so that it makes an exact match to prevent from entering the same directory more than once?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:30:07+00:00Added an answer on June 5, 2026 at 5:30 pm

    You could try searching for sample_8_1/ (i.e., include the following slash). I guess given your code that would be dire.find(name+'/'). This just a quick and dirty approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to capture sub-strings from a string that looks similar to 'some
I'm trying to find out if two strings I have are the same, for
I'm trying to find all subfolders in a file's path that have 'others exec'
I am trying to find a string inbetween two other strings. This function is
I have an instance method that populates a vector of strings. I am trying
Trying to find an example that has css rollover using sprites & sliding door
Trying to find examples of when decorators might be really beneficial, and when not
Been trying to find this online for a while now. I have a SDL_Surface
Am trying to find some text only if it contains english letters and numbers
Im trying to find records in a VARCHAR column that may contain a NUL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.