Jump to content

Number of files as var in javascript


Iven

Recommended Posts

Hello

I am new to HTML and javascript.

I would like to get the number of files of an directory as an var in javascript.

For example: If I have an folder called "C:\Users\media" and I know there are only 10 images in that folder I want the code so that I can have a variable representing the number 10(also this is subject to change like I can add images and then there will be let's say 11 images in the folder and if the pages reload the variable must contain the number 11).

The closest I have come to a solution is this: <input type="file" id="file" multiple /> . However I don't want to select the files I want the files(number of files more specifically) to be automatically updated to a variable instead of select an file and then writing JS to get the length.

 

The only solution I want must be in HTML,javascript,CSS.

If you want to provide a solution using something else(lets say PHP or something I don't know...) please don't.

Thank you so much

PS. I apologize if this topic is in the wrong section on the forums,I want a JS solution so I posted here

Also like I said I am pretty new(learning my self) so if you provide a kind of complex solutions then please just comment in why you used whatever you used.

 

Edited by Iven
Link to comment
Share on other sites

Due to security restrictions, browsers do not give Javascript access to the user's filesystem. Any information about the filesystem could be used by hackers to take control of the user's computer.

Link to comment
Share on other sites

You can access the server's filesystem using a server-side programming language like PHP.

If you want to access files on the user's computer you'll have to create a desktop program in a language like C++ or Java and ask the user to download and run it.

  • Thanks 1
Link to comment
Share on other sites

Awesome I will get on that.

Much appreciated.

Also in another post I made(unrelated) someone said something about using "browser developer tools" to find JS syntax errors.

Can someone please give a link or example on how to do this it will help a lot.

Thanks

Link to comment
Share on other sites

Most browsers will show the developer tools by pressing F12 on the keyboard. If not, you'll have to search the menus and options of the browser. Usually you can also open developer tools by right clicking on a page and selecting "Inspect Element" from the context menu.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...