Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i get images file name from a given folder [duplicate]

I have got a task to display all images inside a folder using jquery.

For that i used the code

var imageFolder = '../../Images/Avatar/';
var imgsrc = imageFolder +'';

I need to get the images file name inside that folder avatar. How can I get the file name. There are lot of image files in that avatar folder also has some txt files.I only need jpg,png,gif images only.

like image 950
Nithin Viswanathan Avatar asked Feb 27 '14 06:02

Nithin Viswanathan


People also ask

How do I find duplicate photos with different names in Windows 10?

Duplicate photo finder and remover software Cisdem Duplicate Finder can automatically scan the locations you specify for duplicate photos. The software detects duplicate photos by content (regardless of filename), so it can also find and remove duplicate photos with different names.

How do I find duplicate photos in a folder?

Download and install Duplicate Photos Fixer Pro. Run the tool > select the location to scan > Add photos or folders to scan. Click Scan for Duplicates. Review scan results > and use Auto Mark feature to select duplicate images > clean them to get a duplicate free photo library.

Does Windows 10 have a duplicate file finder?

Answer: No, Windows 10 does not have a duplicate finder in it yet.


2 Answers

try this way

HTML CODE:

<div id='fileNames'> </div>

JQUERY CODE:

var fileExt = {},
    fileExt[0]=".png",
    fileExt[1]=".jpg",
    fileExt[2]=".gif";
$.ajax({
    //This will retrieve the contents of the folder if the folder is configured as 'browsable'
    url: '../../Images/Avatar/',
    success: function (data) {
       $("#fileNames").html('<ul>');
       //List all png or jpg or gif file names in the page
       $(data).find("a:contains(" + fileExt[0] + "),a:contains(" + fileExt[1] + "),a:contains(" + fileExt[2] + ")").each(function () {
           var filename = this.href.replace(window.location.host, "").replace("http:///", "");
           $("#fileNames").append( "<li>" + filename + "</li>");
       });
       $("#fileNames").append('</ul>');
     }     
  });

Basic logic referred from this SO question Here

Happy Coding :)

like image 104
dreamweiver Avatar answered Sep 29 '22 20:09

dreamweiver


I don't know that it will work or not but you can try this

Give the name of image 1,2,3,4.....

and than show image using for loop like.

var imageFolder = '../../Images/Avatar/';

var imgsrc="";

for(var i=1; i <= totalImage; i++){
 imgsrc= imageFolder +i;

}
like image 43
user2075328 Avatar answered Sep 29 '22 20:09

user2075328