8 years ago
Topic

Hi all, I'm looking for an SQL guru who can help me search and replace the image path in the database of my content type.  I realized all of my images were going into unique folders but I would prefer just one.  I've got a couple of hundred pieces of content so I'm hoping to do this as a query rather than by hand.

table = xxxxx_cck_store_form_mytable
column = cp_flag

Search "images/290/bo.png"
Replace with "images/flags/bo.png"

in all cases the image path only has 3 numbers in the path that I would like to replace with "flags" and leave the filename as is.

so search "images/???" and replace with "images/flags" is what I'm hoping to learn how to do.

Thank you!!!

Get a Book for SEBLOD
4229 Posts
Kadministrator
8 years ago
0
Level 1

You need something like this for mysql

https://techras.wordpress.com/2011/06/02/regex-replace-for-mysql/

MariaDb has this function buil in it seems

https://mariadb.com/kb/en/mariadb/regexp_replace/

Plus you need to write right regex ofc

8 years ago
2
Level 1

Thank you Klas.  Success!

We actually ended up using excel to solve this.  But I sure wish I could get my head around regex better.

export table to excel, highlight colulmn in question and use "text to columns" to break the path into 3 sub columns using "/" as the delimiter.  Fill the ### path column with "flags" and then concatonate to reassemble into a single column.

You might also be interested in a recent tool that I found.  http://nimbletext.com/
This probably could have done similar.  I found nimble text when searching for a way to convert tables to def terms.  Worked incredible, but I now have to learn how to use it as well.  Check it out, I bet you'll find it to be interesting.

Bryan

7 years ago
1
Level 2

Hi Bryan,

Did you manage to prevent the images going to individual folders in the first place?

Thanks

Steviec1

7 years ago
0
Level 3

Oh, yeah, that was easy.  Just change the params on the image upload field to not create the extra folder.

Thanks

Get a VIP membership