13

I want to open a file browser in JavaScript and set a default directory to this file browser. For example, I will like to set the default directory to "C:\My Documents".

How to set a default directory? It's better to use <input type="file"/>, other controls are ok too.

4
  • possible duplicate of control the working directory for <input type="file">? Commented Jul 2, 2013 at 8:17
  • I don't think it is possible. How users with a non-windows OS would use it? And think about the security risk of accessing user's filesystem. Commented Jul 2, 2013 at 8:18
  • I'm currently not sure if it is possible to define a certain location in html5 like images, documents or movies as default. But even if it is now possible, defining a whole path like C:\My Documents (i hope it is not possible) would not make much sens, because the path could change from system to system. Commented Jul 2, 2013 at 8:20
  • My requirement is not limit to <input type="file"/>, others are fine for me if it doesn't support to specify default directory. It's fine if can set images, documents or movies (specific folders) as default. Commented Jul 2, 2013 at 8:30

2 Answers 2

21

This is impossible, as it is a security risk to let website code set any value on the machine.

Also, you can never be sure that directory exists. What if I'm on a Mac? My stuff are in ~/Pictures. What if I installed Windows on D:\?

Sign up to request clarification or add additional context in comments.

2 Comments

If you are developing enterprise software that runs on a single platform you can pretty well be 100% sure a directory exists.
@MichaelPaccione This is Untrue. I just ran into an issue that locks Chrome up completely for 200+ seconds when an NFS share is not available. This happens because my resource is behind a VPN and if the PWD is within this resource and the user is not connected to the network or the VPN it looks like their chrome crashed. I came here to see if this was exploitable and fortunately it's not!
-8

From http://www.pcreview.co.uk/threads/automatically-put-a-default-filename-in-input-type-file-value.2192852/

<input type="file" value="YourDefaultPathAndFilename.AndExtension">

2 Comments

I really would like to it work... I'm sure about the file location but I really dont believe this will work due security reasons; but if you can, I would love to see a working example for javaScript
As one of the downvoters I feel obliged to explain why: this answer appears to be just plain wrong. There's no explanation of whether the responder even successfully used it - only a link to an external discussion. In fact - in the site linked discussion they also say it doesn't work for the same reasons stated in this discussion! Why was it even referenced here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.