Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda