T
T
TempUserMain2014-05-30 15:18:49
JavaScript
TempUserMain, 2014-05-30 15:18:49

Node.js: How to find out the path to an arbitrary file?

There is no js file.
Need to know the path to this file, for example, "C:/<...>/file.txt"?
Tell me, please, how to solve the problem?
Looking ahead, there are "__filename" and "__dirname" functions, but they give the path to the executable js file.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Finnish, 2014-05-30
@finnish

Maybe the path module will help?

var path = require('path');
path.resolve(__dirname, filename);  // Относительный путь до файла от текущей директории

G
green_turtle, 2014-05-30
@green_turtle

Either look for ready-made modules for searching files, or write a search yourself, or try to call some system functions (like "find" in unix)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question