Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8616637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:40:03+00:00 2026-06-12T05:40:03+00:00

I am loading several files in a directory in order to parse some data

  • 0

I am loading several files in a directory in order to parse some data from them. This works great so far, but I would like to know which file I am looking at. So I need the name of the file after it was loaded.
Can anybody help on that?

// gets all files in dir

function updateData(){
  var dirReader = approot.createReader();

  var fail =failCB('Error - Directory for parsing failed to open'); // logs fail...
  dirReader.readEntries(parseData,fail); 
}

// loading each file

function parseData(entries){
  var i;
  for (i=0; i<entries.length; i++) {
    var reader = new FileReader();
    reader.onloadend = createListItem;
    reader.readAsText(entries[i]);
  }
}

// HERE I WOULD LIKE TO KNOW THE NAME !!!!

function createListItem(evt){
    // it gives me all the loaded data. But based on which file it was, I would like to handle it!
  console.log(evt.target.result)
    // lets say something like this
    $('#content').find(   file.name   ).append(evt.target.result);
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:40:05+00:00Added an answer on June 12, 2026 at 5:40 am

    Create a closure around the File to capture the current file. Then you can get the filename.

    An example: http://www.html5rocks.com/en/tutorials/file/dndfiles/#toc-reading-files

    Closure to capture the file information.

    function parseData(entries){
      for (var i=0; i<entries.length; i++) {
        reader.onloadend = (function(file) {
          return function(evt) {
            createListItem(evt, file)
          };
        })(entries[i]);
        reader.readAsText(entries[i]);
      }
    }
    

    And the called function gets an additional argument

    function createListItem(evt, file) {
      console.log(evt.target.result)
      console.log(file.name);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've inherited several PHP scripts that parse data from CSV files and update a
I'm using several 32 bit PNG files in my VS2010 project and loading them
I have several directories of 12 .caf files and am loading them programmatically: NSString
I am loading/unloading several swfs from one main swf. When I load a new
I have several large word lists and I had been loading them in place
I'm planning on getting several JS files from my server asynchronously while the page
I have several classes that need to load some properties files, and I was
In heptasarim.com there are several JavaScript files and plugin loading on every page and
i'm loading several sound files, and want to error check each load. however, instead
I am using several plugins, custom widgets and some other libraries from JQuery. as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.