0

I am migrating website and I changed my mind about url path where my images are stored. Before the path looked like: files/name-of-article/image.jpg now I would like to change it to files/img/name-of-article/image/jpg. How it is possible to replace "files" with "files/img" string? I found following sql code but it works only for replacing whole urll path.

UPDATE field_data_body  SET body_value = REPLACE(body_value,'src="/olddirectory','src="/newdirectory');

Thank you.

2 Answers 2

1

Try the scanner module instead:

http://drupal.org/project/scanner

Search and Replace Scanner can do plain text search-and-replace, or regular expression search-and-replace, against the title, body and text content fields on all nodes in your system. This is useful for finding html strings that Drupal's normal search will ignore. The module is very handy if you are fixing typos in a lot of content, changing the name of your company, or are changing the URL of a link included multiple times in multiple nodes, among other things.

Your sql query might work but this is a little more robust and has a rollback option.

2
  • Hi,how can I find and replace paths with this module? It would be much easier for me to run sql code than to study new module.
    – loparr
    Commented Feb 22, 2013 at 2:50
  • up to you - scanner module is relatively straightforward and a little more robust than trying to find a query string to operate against n fields. Also, again, it has the possibility of rolling back an operation if it doesn't work as expected.
    – schnippy
    Commented Feb 22, 2013 at 18:41
0

Simple sql code like this did the job update file_managed set uri = replace(uri, 'public://', 'public://img')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.