Questions tagged [dirname]
138 questions
3
votes
2 answers
error TS2307: Cannot find module 'path' or its corresponding type declarations. when trying to migrate in heroku app with Knex
I want to migrate a SQlite database:
knex --knexfile knexfile.ts migrate:latest
However this gives the following typescript error:
⨯ Unable to compile TypeScript:
knexfile.ts:1:18 - error TS2307: Cannot find module 'path' or its corresponding type…

lucasbbs
- 349
- 4
- 14
3
votes
2 answers
How do I obtain the directory of the current module in Node.js without using "__dirname" or "import.meta.url"?
OK, in Node.js, when using module.exports you'd use:
__dirname
To obtain the location of the current file.
For example, if you ran it from x.js in folder y, you'd get something like this:
blah/blah/blah/y
Now, I can't use, process.cwd because…

Malekai
- 4,765
- 5
- 25
- 60
3
votes
0 answers
PowerShell eqivalent of POSIX dirname
This question asks about how to get the directory name of a path in a batch script.
How does one do the equivalent of POSIX dirname in PowerShell?

Tom Hale
- 40,825
- 36
- 187
- 242
3
votes
2 answers
Unix C - Compiling for 64 bit breaks "dirname"
I'm using dirname from libgen.h to get the directory path from a filename's path.
This is it's signature:
char * dirname (char *path)
When compiling on a 32 bit machine or using -m32 with gcc, it all works fine.
My code looks like this:
char* path…

jonathanpeppers
- 26,115
- 21
- 99
- 182
3
votes
2 answers
dirname equivalent in Go
I'm studying Go, I don't know if I missed something, but after searching, I wonder: Does dirname in NodeJS have an equivalent in Go? How to get current directory in Go code, or I have to implement one?

necroface
- 3,365
- 10
- 46
- 70
3
votes
2 answers
Going up two or three folders using dirname twice or three times
Take a look at the code
$link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo dirname(dirname($link));
Question 1. Is it elegant to use dirname twice to go two levels up?
Question 2. In case you want to go three levels up, would it be a…

Julian
- 4,396
- 5
- 39
- 51
3
votes
2 answers
PHP get File Directory of an included File
i have the following PHP File Structure:
dir0
dirA
dirA.1
dirA.1.1
fileA.php : dirname(__FILE__).'/docs';
dirA.2
...
dirB
fileB.php:…

Rami.Q
- 2,486
- 2
- 19
- 30
3
votes
1 answer
Getting "Permission denied" on dirname and basename
That's all. They just won't work for me. What did I do wrong this time?
# nquo is: /home/bryan/renametest/C D/y z
# script:
dirn=dirname "$nquo"
echo "dirn $dirn"
bnam=basename "$nquo"
echo "bnam $bnam"
Run result:
…

user2021539
- 949
- 3
- 14
- 31
2
votes
0 answers
Getting 'Not found' after deploying my react web application
I'm trying to deploy my React application on Vercel. After deployment I'm getting 'NOT FOUND' when i'm trying to visit the link. Screen shot attached.enter image description here
This is my index.js file code:
// express acts as a server
import…

Abhishek
- 21
- 2
2
votes
3 answers
ReferenceError: __dirname is not defined in ES module scope building script
Im having a problem with
"ReferenceError: __dirname is not defined in ES module scope" error
import path from 'path'
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import Pages from 'vite-plugin-pages'
import Layouts from…

Chi Chi Huang
- 43
- 1
- 5
2
votes
3 answers
zsh: no such file or directory: - but file exists
Background: I already have a working alias my-tool as follows:
alias my-tool='~/path/to/src/my-tool.py'
I want another alias that depends on that alias' path (so I don't write the path in two places):
alias other-tool=$'$(dirname $(dirname $(which…

Oliver Williams
- 5,966
- 7
- 36
- 78
2
votes
2 answers
How to extract the directory from full file path
I have the following script which prints various file stats, which was kindly supplied by another user (choroba) (link).
Is there a way that this can be amended to report just the directory name of each file and not the full file path with the file…

simonc
- 87
- 7
2
votes
1 answer
How to grab url path to file in php
For sending a link to a email (confirming subscription). i need the path to the file subscribe.php.
On my webserver, the file subscribe.php is in the webroot.
External access will be: http://newsletter.mydomain.com/subscribe.php
This is the link in…

john
- 1,263
- 5
- 18
2
votes
1 answer
Winston logger: set actual caling filename as logging info label
I have a winston logger, and I want to set the filename of the file where the logger is being executed as the label object of the logger info object.
e.g:
[info]:[callingFileName.js] - 19.06.2019 14:09:19: [message]:...
Here is my code:
'use…

MMMM
- 3,320
- 8
- 43
- 80
2
votes
1 answer
How to strip or replace all matches of a pattern from a string in Bash?
I am trying to write the dirname function in Bash so that it doesn't use any external commands.
function dirname() {
local path=$1
[[ $path =~ ^[^/]+$ ]] && dir=. || { # if path has no slashes, set dir to .
[[ $path =~ ^/+$ ]] …

codeforester
- 39,467
- 16
- 112
- 140