Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda