Query to rename file path if it match in filepath table - mysql

In the image I have filepath and parent_path columns, The requirement is if my string is contains in filepath then replace with new string and in parent path too.
Example : E:\Images\Apple_icon.jpg search for "Images" if contains replace with "MyImages", like this=> E:\MyImages\Apple_icon.jpg

update tableName set FILEPATH=REPLACE(FILEPATH,'E:\Images\','E:\MyImages\') ,
PARENT_PATH=REPLACE(PARENT_PATH,'E:\Images','E:\MyImages')

Related

How to use an auto generated filename while saving an EPS/JPG file in Octave5.2 (WINDOWS)?

I am using Octave. The code is:
figure(1)
plot(what ever i want)
file_name = sprintf ("C:/Users/Admin/Dropbox/final/Uniaxial_trial_%d_%d.eps",nxt,nxb);
print -color -depsc file_name
The above did not work. It generates a file with the name file_name and not the string stored in file_name
It exists several syntax for print. Try:
print(file_name,"-color","-depsc")

remove part of string record in mysql

this is my string record on tables in mysql
"ftp://myftp.co/ftp/Media_Gallery//Cartoon/Serries/Shaun_The_Sheep/Shaun_The_Sheep_E015.mkv"
now i want remove "//" at the center of my string after "Media_Gallery"
but when i use replace queries // this query remove // at the first of URL and its wrong
my string after run query would be this scheme:
"ftp://ftp.um.ac.ir/ftp/Media_Gallery/Cartoon/Serries/Shaun_The_Sheep/Shaun_The_Sheep_E015.mkv"
UPDATE Mytable SET name = REPLACE(name, 'y//', 'y/');

MYSQL + Change path + Update substring

I have a question, i have table 'file' with a column 'path' in my DB called Pics.
Each path is like "C:\my folder\pics\pic1.jpg" etc.......
How i do to change:
C:\my folder\pics\
to
C:\my NEW folder\NEW pics\
I try a select for the path folder without the filename like this :
SELECT substring(c1,1,locate(substring_index(c1,'/',-1),c1)-1) FROM t1
that give me "C:\my folder\pics\".
Now i need to update all the column path. What is the correct query. I try this but dont work.
update foto set path = 'z' where path = (SELECT substring(path,1,locate(substring_index(path,'\\',-1),path)-1))
Thanks for sharing
Done.
update foto set path = REPLACE(path,(SELECT substring(path,1,locate(substring_index(path,'\\',-2),path)-1)),'" & TextBox2.Text & "'

split mysql database field into 2 parts

i am saving complete file path in single field now i want to split it. bellow is my current database file path.
Current field name is "video_thumb"
../files/thumbs/2014-Oct/1413648778-sm.jpg
now i want to split it into 2 fields
folder path in one field
i want to split the following to "thumb_path"
../files/thumbs/2014-Oct/
the file name in another field "file_name"
1413648778-sm.jpg
SET #STR = '../files/thumbs/2014-Oct/1413648778-sm.jpg';
SELECT #STR,
REVERSE(#STR) AS REVERSESTR,
REVERSE(SUBSTRING(REVERSE(#STR),1,INSTR(REVERSE(#STR),'/') - 1)) FILENAME,
REPLACE
(#STR,
REVERSE(SUBSTRING(REVERSE(#STR),1,INSTR(REVERSE(#STR),'/') -1))
,''
) AS THUMB;
I have left all the steps in to illustrate the solution
Try with a query like this :
select '/files/thumbs/2014-Oct/1413648778-sm.jpg' path_and_filename,
replace('/files/thumbs/2014-Oct/1413648778-sm.jpg', substring_index('/files/thumbs/2014-Oct/1413648778-sm.jpg', '/', -1), '') path,
substring_index('/files/thumbs/2014-Oct/1413648778-sm.jpg', '/', -1) filename
from myTable
You will have 3 fields :
path_and_filename : Original Data
path : Only path string
filename : Only filename string
XaV

Change image name and update into same table using mysql query

I want to change image name in table like below.
image name : test.png
replace with : test_E.png
I want _E at end of all image name in table using mysql query.
Use replace function
update <table>
set image=replace(image,'.png','_E.png')
you could use this, if the image extension is not same in the table
update <table>
set image=concat(substring(image,1,locate('.',image)-1),'_E',
substring(image,locate('.',image),lenght(image)))
You can use string functions of MySQL query:
UPDATE TABLE SET IMAGE_NAME = CONCAT(SUBSTR(IMAGE_NAME,(CHAR_LENGTH(IMAGE_NAME) - 4)),
'_E' , SUBSTR(IMAGE_NAME, -4)) WHERE ID = <put record id>;
SUBSTR(IMAGE_NAME,(CHAR_LENGTH(IMAGE_NAME)-4)) would return name of file - assuming extension is of 3 chars. For 'test.png' above function would remove '.png' and function would return 'test'
SUBSTR(IMAGE_NAME, -4) would return last four chars of string - so 'test.png' would return '.png'
using concat you can concat 'test', '_E' and '.png' - returning 'test_E.png'
Please refer to string functions reference of MySQL for further use
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html