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

  • SEARCH
  • Home
  • 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 389395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:51:46+00:00 2026-05-12T15:51:46+00:00

I have a file which I use to centralize all strings used in my

  • 0

I have a file which I use to centralize all strings used in my application. Lets call it Strings.txt;

TITLE="Title"
T_AND_C="Accept my terms and conditions please"
START_BUTTON="Start"
BACK_BUTTON="Back"
...

This helps me with I18n, the issue is that my application is now a lot larger and has evolved. As such a lot of these strings are probably not used anymore. I want to eliminate the ones that have gone and tidy up the file.

I want to write a python script, using regular expressions I can get all of the string aliases but how can I search all files in a Java package hierarchy for an instance of a string? If there is a reason I use use perl or bash then let me know as I can but I’d prefer to stick to one scripting language.

Please ask for clarification if this doesn’t make sense, hopefully this is straightforward, I just haven’t used python much.

Thanks in advance,

Gav

  • 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-05-12T15:51:46+00:00Added an answer on May 12, 2026 at 3:51 pm

    Assuming the files are of reasonable size (as source files will be) so you can easily read them in memory, and that you’re looking for the parts in quotes right of the = signs:

    import collections
    files_by_str = collections.defaultdict(list)
    
    thestrings = []
    with open('Strings.txt') as f:
      for line in f:
        text = line.split('=', 1)[1]
        text = text.strip().replace('"', '')
        thestrings.append(text)
    
    import os
    
    for root, dirs, files in os.walk('/top/dir/of/interest'):
      for name in files:
        path = os.path.join(root, name)
        with open(path) as f:
          data = f.read()
          for text in thestrings:
            if text in data:
              files_by_str[text].append(path)
              break
    

    This gives you a dict with the texts (those that are present in 1+ files, only), as keys, and lists of the paths to the files containing them as values. If you care only about a yes/no answer to the question “is this text present somewhere”, and don’t care where, you can save some memory by keeping only a set instead of the defaultdict; but I think that often knowing what files contained each text will be useful, so I suggest this more complete version.

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

Sidebar

Related Questions

I have a text file,which I use to input information into my application.The problem
I have a mp4 file which is to be used in an application. Currently
I have a .rc file which is used to include some text data in
I have a txt file which actually is a html source of some webpage.
I have File Upload form which users use to upload certain files on the
I have a .xsd file which I use to generate code with the xsd.exe
Updated According to comments: I have outlog.txt file which contains multiple filenames, e.g: 2345_535_Dell&HP_3PAR_DEAL.txt
I have a common HTML header file which I use in several PHP files.
I have A header file which contains declaration of a function, let's call it
I have a file which is an XML representation of some data that is

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.