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

  • Home
  • SEARCH
  • 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 8304033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:42:33+00:00 2026-06-08T17:42:33+00:00

How do I get access to the the arguments of fs.read , fs.stat …

  • 0

How do I get access to the the arguments of fs.read,fs.stat… methods from within a callback?

For instance if I want to process a file based on its size
Following (coffeeScript) code snippet

#assuming test1.txt exists
filename = "./test1.txt"
fs.stat filename, (err, stats) ->
  data = filename:filename,size:stats.size
  console.log data
  #further process filename based on size
filename = "./test2.txt"

prints

{ filename: './test2.txt', size: 5 }

as filename is set to “./test2.txt”. If I process/read the file using filename variable within fs.stat callback it would use test2.txt which is not intended.

What I expect to see within callback is

{ filename: './test1.txt', size: 5 }
  • 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-08T17:42:35+00:00Added an answer on June 8, 2026 at 5:42 pm

    Don’t think there’s a way to do this right now. Might be a good thing to add to node at some point. If you’re going to do this a lot you can put fs.stat in a friendly wrapper.

    var friendlyStat = function(filename, callback){
        fs.stat(filename, function(err, stats){
            stats.filename = filename
    
            if(err) {
                callback(err);
            } else {
                callback(err, stats);
            }
        })
    }
    
    friendlyStat('test1.txt', function(err, stat){ console.log(stat.filename);});
    friendlyStat('test2.txt', function(err, stat){ console.log(stat.filename);});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get access to the data-global-id value in the following markup and
I'm using the JDBC template and want to read from a database using prepared
I have a parent and child process, and the parent can read output from
I want my PHP Zend Application to get access to the database. Because the
I am trying to get my program to read a value from a particular
How can you get access to the dynamically-changing coordinates of a draggable object? I
Is there anyway to get access to stackoverflow's awesome tagging system? I would like
I am trying to get access to all the endpoints that a particular contact
I'm trying to get access to the Google Drive API using RestKit on iOS
I am looking to get access to all HTTP traffic on my machine (my

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.