0

just a quick question,

mission is to get a folder directory name. example: _C:\ThisFolder\myFolder_.

and I've used html input type="file" but I'm only able to get the file name, plus type="file" works like one want to upload something, while I just want to get the folder path of user selection.

<label> Update to  : </label>
<input type="file" class="form-control" id="dirpath" name="dirpath" directory />

is there any other approach that I could use, please advice, thanks.

4

3 Answers 3

2

Due to security reasons browser does not allow it. Browser has no access to the file system. If you need the file's path for reading a file you can use the FileReader API instead.

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

1 Comment

what I need is something like selecting a folder to save file before begin downloading it? can't I do something like that?
0

Try this code,

   
    	$('#dirpath').on('change',function ()
            {
                var filePath = $(this).val();
                console.log(filePath);
            });
<label> Update to  : </label>
    <input type="file" class="form-control" id="dirpath" onchange="fileget(event)" name="dirpath" directory />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

3 Comments

gives me this error Uncaught TypeError: Cannot set property 'onchange' of null
did you insert the jquery ?
sorry, my bad..it does working, but what I need is something like selecting a folder to save file before begin downloading it.
0

Maybe you can just use it like this:

<label> Update to  : </label>
<input type="file" class="form-control" id="dirpath" name="dirpath" directory onSubmit = getPath()/>

<script language="javascript" type="text/javascript">
function getPath() {
     var inputName = document.getElementById('dirname');
     var Path;

     Path = inputName.value;
}
</script>

Comments

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.