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 8610819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:13:02+00:00 2026-06-12T04:13:02+00:00

I am writing a library in Dart and I have static files under the

  • 0

I am writing a library in Dart and I have static files under the library folder. I want to be able to read those files, but I’m not sure how to retrieve the path to it… there is not __FILE__ or $0 like in some other languages.

Update: It seems that I was not clear enough. Let this help you understand me:

test.dart

import 'foo.dart';

void main() {
  print(Foo.getMyPath());
}

foo.dart

library asd;

class Foo {
  static Path getMyPath() => new Path('resources/');
}

It gives me the wrong folder location. It gives me the path to test.dart + resources/, but I want the path to foo.dart + resources/.

  • 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-12T04:13:04+00:00Added an answer on June 12, 2026 at 4:13 am

    As mentioned, you can use mirrors. Here’s an example using what you wanted to achieve:

    test.dart

    import 'foo.dart';
    
    void main() {
      print(Foo.getMyPath());
    }
    

    foo.dart

    library asd;
    
    import 'dart:mirrors';
    
    class Foo {
      static Path getMyPath() => new Path('${currentMirrorSystem().libraries['asd'].url}/resources/');
    }
    

    It should output something like:

    /Users/Kai/test/lib/resources/

    There will probably be a better way to do this in a future release. I will update the answer when this is the case.

    Update: You could also define a private method in the library:

    /**
     * Returns the path to the root of this library.
     */
    _getRootPath() {
      var pathString = new Path(currentMirrorSystem().libraries['LIBNAME'].url).directoryPath.toString().replaceFirst('file:///', '');
      return pathString;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a library and I want to have an interface public interface
I have been writing a library for my project (for now I am using
I'm developing an app in C++/CLI and have a csv file writing library in
I'm writing a library and I want to put documentation in my functions so
I'm writing a library that needs to have some code if a particular library
I'm writing a library that contains some hash functions. I want one of the
I'm writing a library for C#. I'm wondering if it's possible to only have
I am writing a library for efficient number processing. I have to support different
Assuming we are writing a library and that we want to provide fine grain
I am writing a library which may set headers. I want to give a

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.