Search Replace in MySQL: remove directory structure but keep filename -
i changing directory structures in drupal installation , need remove path data except file name itself.
so basic structure is:
+-------------+--------------+---------+-----------+-------------+----------+-------+----------------------------------------------------------------------------------+-----------------------+ | entity_type | bundle | deleted | entity_id | revision_id | language | delta | field_filename_value | field_filename_format | +-------------+--------------+---------+-----------+-------------+----------+-------+----------------------------------------------------------------------------------+-----------------------+
the filename stored in field_filename_value
. here's sample record:
+-------------+--------------+---------+-----------+-------------+----------+-------+----------------------------------------------------------------------------------+-----------------------+ | entity_type | bundle | deleted | entity_id | revision_id | language | delta | field_filename_value | field_filename_format | +-------------+--------------+---------+-----------+-------------+----------+-------+----------------------------------------------------------------------------------+-----------------------+ | node | presentation | 0 | 11 | 11 | und | 0 | /really long path name/with lots of words/167 clarence ashley - coo coo bird.mp3 | null | +-------------+--------------+---------+-----------+-------------+----------+-------+----------------------------------------------------------------------------------+-----------------------+
that ridiculous filename value needs changed from:
/really long path name/with lots of words/167 clarence ashley - coo coo bird.mp3
to this:
167 clarence ashley - coo coo bird.mp3
setting aside bad practice of using spaces in file/directory names, how correct this? possible using mysql features alone?
as added challenge, files may more 2 directories deep.
use substring_index
select substring_index('http://www.example.com/dev/archive/examples/test.htm','/',-1)
(both above
how use easy, explain, select last index of / , substring function cut off left of it
Comments
Post a Comment