Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers

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.

share|improve this answer
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 Feb 22 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 Feb 22 at 18:41

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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