Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
58 views

Robust way to get the current URL path

How to get current URL path with a trailing slash? Is there a robust way to have: example.com => / example.com/ => / example.com/index.php => / ...
Basj's user avatar
  • 46k
0 votes
2 answers
42 views

My terminal isn't showing me the dirname in Python, I write the dir name but it doesn't return anything

import os father_dir = input("Type your directory: ") try: def return_dir_father(dir): return os.path.dirname(dir) res = return_dir_father(father_dir) print(res) ...
Saulo's user avatar
  • 7
0 votes
0 answers
102 views

__dirname not found in yargs module when using puppeteer

import { Component } from '@angular/core'; import { RouterOutlet } from '@angular/router'; import * as cheerio from 'cheerio'; import * as puppeteer from 'puppeteer'; @Component({ selector: 'app-...
ab1428x's user avatar
  • 804
1 vote
0 answers
107 views

__dirname is not defined in ES module scope In AWS Lambda Puppeteer

import * as fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; import puppeteer from 'puppeteer-core'; const __filename = fileURLToPath(import.meta.url); // get the resolved ...
Mohit's user avatar
  • 11
-2 votes
1 answer
51 views

javascript detecting file path

i am going to make a npm package that can check the main file if it's exist how can i detect the file path? main file index.js const exampleCheck = require("exampleCheck") exampleCheck(...
LeiamNash's user avatar
0 votes
0 answers
29 views

Dirname doesn't follow command till the end of the path

I want to use dirname to specify my root directory, but it always stops specifying the folder one before the final folder. I want to set my working directories and have done so in the beginning of my ...
Anjana's user avatar
  • 1
0 votes
1 answer
202 views

Using basename dirname to split a file path and to run the run

I have a generic filepath- /home/aa/bb/cc/d.txt and want to script something like this- so in the script, one thing would be for it to take that /path/to/testcase/d.txt And split it into working_dir = ...
user18726987's user avatar
0 votes
1 answer
38 views

How to get extract directory name from the full filepath name of a file using glob recursive

I have two folders cats and dogs with 5 jpeg images in each cat1.jpeg cat2.jpeg..... dog1.jpeg dog2.jpeg etc... I want to write a CSV file that looks like this 1,./images/trainnew/dogs/dogs2.jpg,dogs ...
Chandrakala Gowda's user avatar
1 vote
1 answer
275 views

__dirname not giving the proper file path in TypeScript

I have been trying to use __dirname for fs.readFile. But __dirname doesn't seem to give me the correct file path. To be more specific, I am trying to develop a plugin for the Obsidian app and the path ...
Kevin Tommy's user avatar
1 vote
1 answer
3k views

How can I produce __dirname pointing to the root directory from within an EJS module located in a subdirectory?

I am using EJS modules and would like to refer to all files with reference to the root directory. In the past, this would be __dirname, but per this description it is different. These instructions ...
user3877654's user avatar
  • 1,253
2 votes
0 answers
62 views

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 ...
Abhishek's user avatar
0 votes
2 answers
848 views

fs.readFileSync & path

I am relatively new to Node.js and have been looking around but cannot find a solution. I want to read files from a subfolder 'filesPath'. I don't know how to write fs.readFileSync correctly That is ...
Marcin's user avatar
  • 13
11 votes
4 answers
20k views

what does fileURLToPath(import.meta.url) do?

Okay, so I was following a MERN stack tutorial and the tutor wrote out some lines of code but didn't really explain them well. this is the code: const path = require("path"); const { ...
gerard's user avatar
  • 491
0 votes
0 answers
132 views

__dirname always returns "/" no matter which file I console log it out

console.log("__dirname: ", __dirname); no matter which file or nested file I place the above code in, it always logs "/".
Bear Bile Farming is Torture's user avatar
0 votes
1 answer
553 views

(eval):66: command not found: dirname

After i set anaconda there is an error Iterm error : (eval):66: command not found: dirname ################################## which python -> /opt/anaconda3/bin/python which dirname -> /usr/bin/...
Climbing_holic's user avatar
0 votes
0 answers
44 views

PHP relative paths

suppose that I am working on a similar server PHP, with more projects, each of them with multiple subfolders and includes. Let's concentrate on proj1: /var/www/html /proj1 /inc ...
p-marco's user avatar
  • 59
4 votes
4 answers
8k views

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' ...
Chi Chi Huang's user avatar
1 vote
0 answers
109 views

Directory path not defined error in Node - ReferenceError

Trying to get the directory path of my current script in NodeJs using "__dirname". I'm getting Reference Error. What can be wrong Here's the code (though it's part of a larger code base): ...
Sonola Moyo's user avatar
2 votes
3 answers
3k views

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):...
Oliver Williams's user avatar
1 vote
1 answer
604 views

I am trying to send an html file as a response in my simple express server route to "/" using res.sendFIle, but it is not seeming to work

This is the code I have so far for my router. Just a basic GET request to the root of localhost:3000. function fileSending(req, res) { res.sendFile(__dirname + "/views/index.html"); }; app.get("/"...
Logan Aaron's user avatar
3 votes
1 answer
1k views

PowerShell equivalent of “dirname $0” from bash

I've used dirname "$0" which is an idiom to determine the path of the running script in bash, e.g.: pushd "$(dirname "$0")" data_dir="$(dirname "$0")/data/...
minhee's user avatar
  • 5,818
3 votes
2 answers
9k views

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: ...
lucasbbs's user avatar
  • 307
0 votes
0 answers
294 views

How to input forward slash to the array shell

I want to separate the text from each other with forwardslash and in console nothing appears with this code (I also tried to make variable sep="/" which I put behind the ${arr[i]}) #!/bin/...
Michael Hajný's user avatar
-1 votes
2 answers
211 views

How can I go two level back in perl using dirname?

I have a value stored in a variable $var1="/home/PPP/Testing/dir2/file1"; and this is a real path in my linux system. Now, using the value of $var1, I want to extract the value of $var2. I ...
PPP's user avatar
  • 359
0 votes
0 answers
338 views

PHP SSH2 Connection, ssh2_exec does not seem to support Executing dirname(__DIR__) or $_SERVER['DOCUMENT_ROOT'] on Remote Server

I been trying for hours to get the name of the public folder on a remote server using an ssh2 connection. On some servers the public directory is "public_html" but others may be "htdocs&...
Jim Dandy BOA's user avatar
0 votes
1 answer
2k views

In Bash, the dirname command is not found

I'm writing a simple script: #!/bin/bash PATH=$(readlink -f $0) echo $PATH DIR_PATH=$(dirname $PATH) echo $DIR_PATH However, the output is: /home/kalyani/Desktop/Linux/Proj/script.sh ./script.sh:line ...
Kalyani Rajalingham's user avatar
0 votes
1 answer
103 views

Current file targeting function returning an expected default value

I'm trying to use location_directory= os.path.dirname(os.getcwd()) for a folder location, but this function is returning a directory above, I will explain with results and what I ask for help on how ...
Raphael Moral Piazera's user avatar
1 vote
1 answer
2k views

Why does __dirname does not return an absolute directory path?

I am trying to read a file with fs.readFileSync and I'm running into some issues locating that file with __dirname. This is my directory structure: /Users /me /Documents /myapp /...
Jake Wright's user avatar
2 votes
2 answers
1k views

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 ...
simonc's user avatar
  • 87
0 votes
1 answer
815 views

node.js multiple __dirnames

Can I put more than one file/directory down with __dirname ? example: const dirPath = path.join(__dirname, ‘/candles’); const dirPath = path.join(__dirname, ‘/lightbulbs’); const dirPath = path.join(...
user avatar
0 votes
0 answers
54 views

Get string from array scanned directory

I have this array which is the result of a directory scan on my external drive where I have stored my e-books collection: Array ( [Asa Larsson] => Array ( [De tweede zonde (...
Franco's user avatar
  • 2,329
0 votes
1 answer
945 views

Difference between app.use(express.static(__dirname + '/public')) and app.use(express.static('public'));

I wonder if the following two are the same. (1) app.use(express.static(__dirname + "/public")); (2) app.use(express.static("public")); Because I think as long as (2) exists in the ...
sekai_no_suda's user avatar
3 votes
2 answers
2k views

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/...
Malekai's user avatar
  • 4,951
3 votes
0 answers
722 views

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's user avatar
  • 46.5k
0 votes
1 answer
766 views

Express routing static file: Failed to load module script

I'm serving my Angular 9 application the same way I always have, and this is the first time I'm experiencing this issue. I keep getting the following error: "Failed to load module script: The ...
Lewis Morgans's user avatar
-1 votes
1 answer
129 views

I fail to understand the following dirname() function code

OS: Centos PHP: 7.3 I am following a beginner's course by Kevin Skoglund about PHP. These are a few lines from the code. I understand define() and dirname() functions. I just don't understand what is ...
Taimur Falak's user avatar
0 votes
1 answer
377 views

bash: unable to trim path with "dirname" - path is a directory

According to dirname --help, command dirname /usr/bin/sort will output /usr/bin So I tried this: 1 #!/bin/bash 2 3 rawPath="${1}" 4 trimmed=dirname $rawPath 5 echo $trimmed And ran the ...
kamokoba's user avatar
  • 577
0 votes
2 answers
2k views

In nodejs, how can I use '_dirname' in ejs file type?

I am trying to display an image in an EJS file and managed to get the file name, however, I would need the relative path, i.e. __dirname + filename to display that image.
omercheema619's user avatar
0 votes
1 answer
379 views

Node Module path to relative files

So I have written a short node module (module1) as a wrapper for a binary (.exe) that can be called via command line. This is how I get the path to the binary to execute the .exe with ...
rufreakde's user avatar
  • 632
2 votes
1 answer
73 views

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://...
john's user avatar
  • 1,273
1 vote
0 answers
21 views

Has anyone had a problem with python opening a file using dirname and have a double set of backslashes added to the file name?

I'm working on a simple application to upload an audio file to IBM Watson. I'm developing in Python using Anaconda, and the Spyder IDE on Windows 10. I'm running across an error I've not encountered ...
vmatman69's user avatar
0 votes
3 answers
689 views

Bash - dirname not working with substitution

When using find with $(dirname {}), it always just outputs "." as the dirname. E.g. for: find . -name \*.h -exec echo {} \; -exec echo $(dirname {}) \; outputs: ./folder/folder.h . ./folder/...
Jodo's user avatar
  • 4,763
0 votes
1 answer
276 views

In Bash scripting, how to change directory to a file's directory path using the function `dirname`?

I would like to change directory to that of a file by defining an alias: alias direc=`cd | echo dirname "$1"` but this doesnt work. Any ideas are appreciated for how I can restructure this.
user321627's user avatar
  • 2,544
1 vote
0 answers
161 views

Trying to get file name and folder name with space

I'm trying to get my folder name and file name (without extension, but i figure out doing without extension). if I can get in array that will be great but I'm still working on space problem. its ...
Kai's user avatar
  • 11
2 votes
1 answer
2k views

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:...
MarcL's user avatar
  • 3,593
1 vote
3 answers
1k views

How to extract filenames with two file extensions? [closed]

I have a folder containing multiple files which have the double extension ".nii.gz". I want to extract the filenames using os.path.basename but this function returns the filenames only with the first ...
Johannes Wiesner's user avatar
-2 votes
1 answer
89 views

how skip some specific files in multiple subfolders in matlab?

I need to skip some specific files in different sub-folders. So I tried by line "if filename" in the snippet that if the filename not contains raw, info, do some operations, but it doesn't work. I ...
AI_NA's user avatar
  • 346
-1 votes
1 answer
77 views

Can't upload my custom plugin because of a Warning: dirname()

I have created a custom wordpress plugin in local. I wanted to upload it on a website but now when I try to activate I get a error. This is the error: Warning: dirname() expects exactly 1 parameter, ...
kcr's user avatar
  • 37
0 votes
1 answer
68 views

Changing/Replace 1st dot in every generated jpg filename from video to remain single dot

my site is using ffmpeg to generate a thumbnail jpg for every video being uploaded. The code as below: // get the videos uploaded foreach ($videos as $video) { if ($profile_author_id == $userid ||...
Mr.AX's user avatar
  • 1
0 votes
1 answer
114 views

Having problem with path (nodejs botbuilder)

I'm working on a bot using Bot Framework, .env file and a JSON file. The problem is I can't seem to get the icon to show up unless I set the path manually as shown below: var invite = new Welcome(...
Mackhem Chuah's user avatar