How to get the number of images in a folder with Javascript / Jquery

0

I tried to use this function:

function getCount(foldername)
    {
      var myObject, f, filesCount;
      myObject = new ActiveXObject("Scripting.FileSystemObject");
      f = myObject.GetFolder(foldername);
      filesCount = f.files.Count;
      document.write("The number of files in this folder is: " + filesCount);
    }

However, I get the error: Uncaught ReferenceError: ActiveXObject is not defined

Does anyone know an effective way to get the total number of image files in a folder with Javascript/Jquery ? To facilitate, it may be the count of everything in the folder, as there is no possibility of there being another type of non-image file.

    
asked by anonymous 01.06.2015 / 20:13

1 answer

1

It is not possible to do with client-side JavaScript because the browser can not access the files of the computer (except in specific situations like uploading files).

If you need to count the files on client-side , you can extension for Chrome , knowing that it will only work in this browser.

If you need to count the files on the server, you need to use server-side language such as PHP, Python, Ruby, or even JavaScript with node.js. For example, in PHP it would look like this:

$fi = new FilesystemIterator('/caminho/para/a/pasta');
echo "Quantidade de arquivos: " .iterator_count($fi);
    
01.06.2015 / 22:32