Today I have been working with an sql database which corresponds to a folder full of images which had the format like this


This was because they had been uploaded to a website by an application which renames the files to make them friendly to Google, the original format was:


The end result was the application had placed underscores around the hyphons.

I am not 100% certain but I am sure that it isn't good SEO for the site as the filename doesn't help Google to understand the image that it is looking like, it would be far better to remove the hyphons and only leave a single underscore. (This doesn't get around the issue of the file name not making a great amount of sense to Google.

If I was to spend more time I would look to rename this particular file and the others named similary to grange_hill_tv_school_year_2_sunflower_yellow_sweatshirt.png

So how do you rename 1252+ files which have all got a common element that needs rewirting, I used Windows 10 the PowerShell as it's installed in Windows 10 and easy to use.

First backup the files you want to rename so if the automated renaming doesn't work you don't mess up the original file names.

Within an explorer window which is opened at the location that you want to make the changes, press Shift and Right Click the mouse button.

Select Open PowerShell window here.

If your example is the same as mine then you just need to enter the following into the PowerShell window and press enter,

get-childitem | rename-item -newname { $ -replace "_-_","_" }

If you have a different pattern you wish to replace, then edit the bits inbetween the speach quotes. The first part is what your want to change the second is what you want to replace it with.

PowerShell rename example 1

If you have files in a folders within the folder wher you opened the PowerShell window you can tell it to apply the changes to them as well with the following change,

get-childitem -recurse | rename-item -newname { $ -replace "_-_","_" }


The sql file which also needed updating with the new file names was simply edited using notepad++ which is a powerful text file editor which I just used find and replace to edit the required parts. Depending on what your looking at replacing within a file be aware that it may match items that you don't want changing!