Tag: web development

Searching lots of code for one small line

After some shifting around of the team, at work I ended up being responsible for our websites. While most of the day-to-day work was simply making edits through the WordPress interface, this also meant maintaining the back-end code which was previously developed by contractors. I did not have a good sense of the architecture or structure of the source code and was not in touch with the original developers.

By inspecting the site I could see which element or function I wanted to edit, but I did not always know which file I would find it in. I put together a little Python script to help me out.

It’s a function that takes the string you are looking for, for example a PHP function or CSS class, and a file extension to search through, for example “.php”. Run it in the parent directory you want to start searching through and it will look through all files, including files in subdirectories. It then returns a list of all files containing your string.

Check it out on my GitHub.

Navigation