Selecting directory/directory in an input

Asked

Viewed 3,295 times

4

I’m trying to create something that looks like a input type="file", Only instead of uploading a file, you’d have to choose a folder. Something like the "Save As" dialog, where we choose the folder to store the file.

inserir a descrição da imagem aqui

In this example, I would fetch the folder C:/Users/cesarcacao/Desktop

I’d like to put some attempt at code, but I haven’t been able to build anything concrete.

  • But you want to select the path of that directory?

  • Yes, the game goes around a bit. For example, in the image I put, I would fetch the folder C:/Users/cesarcacao/Desktop

1 answer

3


There is an attribute called webkitdirectory, on the G+ page of Addy Osmani he explains better how it works, here a demo.

<input type="file" multiple webkitdirectory id="pasta"/>

I tested it here and it worked on Chrome/Opera.

For safety reasons current browsers do not allow you to get the full file path. Only IE7 down, source

  • What we need is to select only the path of the directory...

  • Yeah, that’s what I’m trying to do, and that’s why I haven’t marked the answer as correct... I’m actually not getting a folder Lert

  • @Cesarmiguel For security reasons current browsers do not allow this. Only IE7 down allows this. http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx

  • @Laerte, add this information in your reply, to answer my question and be able to mark sff

  • Done, @Cesarmiguel.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.