0

I would like to create an .html file with all the pictures that are in a folder. I am not really used to programming, so I would like a solution quite simple, without having to get specific programs to code in JS or PHP.

I found the perfect solution on a topic on this website, but I would like to add some extra-features and I don't know how. This is the method I found witten by Marged : Put all images from directory into HTML

If the list of files is static (you didn't mention if they are created dynamically or not) and you are using Windows a simple approach like this will do:

for %i in (*.jpg) do echo ^<img src="%i" /^> >> all.html

This will create a all.html file which includes references to your jpgs. Simply run the command from a command line window in the directory where your images are stored.

It works great, there is one major improvement I would like to add and I would need your help for that :

  • Right now, it finds all the pictures in the main folder. I would like it to look for all the pictures in every sub-folders and sub-sub-folder of this main folder. Is that possible ?

There are also two little things that bother me but not of great importance :

  • I changed the code so it also looks for .png files : for %i in (*.jpg *.png) do echo ^<img src="%i" /^> >> all.html . It sorts pictures in alphabetical order, but firts all the jpg and then all the png, is it possible to "mix" them together ?

  • Is it also possible to add a random way of sorting the pictures ?

Thanks a lot for your answers :)

  • 2
    Please read [ask]. Ask one focused question per post. Also if you're using `php` I suggest tagging it with `php` – T J May 06 '21 at 11:39
  • Hi TJ, thanks for the tips. I said I dindn't know how to code in php, so I'm not gonna tag it. My questions are quite focused as well I think. If you want so, I can put only the first one. The two others are anecdotic but related to the same problem, I'm not going to make 2 other posts just for them. Thanks – vaatimidona May 06 '21 at 11:42
  • Your code is in `php` and if you want people who know `php` to see your post and give answers you should tag it. Tags are not for showing your own skills. – T J May 06 '21 at 11:44
  • I'm not great at coding but this is a command line code for windows console. And it's not about skills, you can read my first message : I would like to find a light and simple solution like the one I linked, I don't want to have to deal with php that requires a specific program to be opened. Thanks – vaatimidona May 06 '21 at 11:47
  • My bad I thought it is `php` and not bash (whatever windows cmd is) – T J May 06 '21 at 11:52
  • No problem (I am really not used to coding so it's a bit confusing for me sometimes) – vaatimidona May 06 '21 at 11:54
  • `FOR /F "delims=" %G IN ('dir /b /s *.jpg *.png ^|sort') DO ECHO %G` – Squashman May 06 '21 at 13:31
  • @vaatimidona I don't agree with closing your question. Please have a look at https://gist.github.com/Reino17/900aac57dc1609796ac80bdddb69af37. – Reino May 07 '21 at 14:01
  • @Squashman - thanks a lot, I'll try to work it out with this ! – vaatimidona May 18 '21 at 16:32
  • @Reino - thank you, I am answering you on the post you made on github :) – vaatimidona May 18 '21 at 16:33

0 Answers0