Assuming your image files are contained in a single directory:
$ ls -al ./folder_img/*.png
-rw-rw-r-- 1 lacobus lacobus 349237 Jul 4 18:03 ./folder_img/alpha.png
-rw-rw-r-- 1 lacobus lacobus 312568 Jul 4 18:03 ./folder_img/beta.png
-rw-rw-r-- 1 lacobus lacobus 159315 Jul 4 18:03 ./folder_img/delta.png
-rw-rw-r-- 1 lacobus lacobus 2453952 Jul 4 18:03 ./folder_img/episilon.png
-rw-rw-r-- 1 lacobus lacobus 482526 Jul 4 18:03 ./folder_img/gamma.png
-rw-rw-r-- 1 lacobus lacobus 848590 Jul 4 18:03 ./folder_img/omega.pn
You can use the utility find
to generate an SQL script from the image files contained in that directory, in a nonrecursive way. The following example saves an SQL script to the file script.sql
, look at you:
$ find ./folder_img -maxdepth 1 -iname "*.png" -type f -exec \
echo "INSERT INTO tb_imagem (nome_arquivo) VALUES ('{}');" \; > script.sql
Exit (script.sql
):
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/delta.png');
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/alpha.png');
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/gamma.png');
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/beta.png');
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/episilon.png');
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/omega.png');
To run the generated script in your database:
$ mysql -h [servidor] -u [usuario] -p [senha] -D [database] < script.sql
Thanks for your attention I’ll test...
– MagicHat