Directory Chooser in HTML Page

Directory Chooser in HTML page

Can't be done in pure HTML/JavaScript for security reasons.

Selecting a file for upload is the best you can do, and even then you won't get its full original path in modern browsers.

You may be able to put something together using Java or Flash (e.g. using SWFUpload as a basis), but it's a lot of work and brings additional compatibility issues.

Another thought would be opening an iframe showing the user's C: drive (or whatever) but even if that's possible nowadays (could be blocked for security reasons, haven't tried in a long time) it will be impossible for your web site to communicate with the iframe (again for security reasons).

What do you need this for?

Folder Choose in Html

I hope this can help you

you can see the folder name in alert when select a file

<script type="text/javascript">  function getfolder(e) {    var files = e.target.files;    var path = files[0].webkitRelativePath;    var Folder = path.split("/");    alert(Folder[0]);  }</script>
<input type="file" id="flup" onchange="getfolder(event)" webkitdirectory mozdirectory msdirectory odirectory directory multiple />

Select folder location in HTML input

No on clientside with plain html and javascript it isn't possible. Your browser handle file downloads. So you can only specify download location in the browser settings!

There are solutions for IE and Chrome but this is very browser specific:

For chrome you can use FSO.js, which is a JavaScript library for temporary and permanent client-side file storage.

In IE you can create an ActiveXObject like this:

// initialize ActiveXObject and create an object of Scripting.FileSystemObject.  
var fso = new ActiveXObject("Scripting.FileSystemObject");

// creates a folder with specified name at the specified location
fso.CreateFolder("C:\\Temp\\myFolder");

fso = null;

html5/Javascript - How to get the Selected folder name?

html:

<input type="file" id="FileUpload" onchange="selectFolder(event)" webkitdirectory mozdirectory msdirectory odirectory directory multiple />

javascript:

<script type="text/javascript">
function selectFolder(e) {
var theFiles = e.target.files;
var relativePath = theFiles[0].webkitRelativePath;
var folder = relativePath.split("/");
alert(folder[0]);
}
</script>


Related Topics



Leave a reply



Submit