Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Get directory name in input field

I have some specific questions that I still haven't found any material on forums that could help me.

I need to get the name of the folder I select to upload. I know that for security reasons I can't get the full path, but I would like to get at least the name of the folder I selected. Example:

<input type="file" id="fileToUpload" webkitdirectory directory/>

When selecting a folder, I want to get its name, I don't care about the name of the files inside it, only the folder name. Another problem would be that I also need to get the name even if the selected folder doesn't get any files.

EDIT:

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


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

With this code below I get what I want, which is the name of the selected folder, but if the selected folder doesn't have any content inside it doesn't return anything.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

does this solve your question

  <body>
    Hello world

  <script>
    function get_name(){
      var check = document.getElementById("fileToUpload").value;

      const arr = check.split("\\");
      console.log(arr);
      console.log("Is this your folder : " , arr.at(arr.length -1) );
      console.log(check);
      

    }
    </script>
    <input type="file" id="fileToUpload" onchange="get_name()" webkitdirectory directory />


    
  </body>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!