relative-path

Get relative path of a File path? [duplicate]

浪子不回头ぞ 提交于 2020-01-11 06:42:06
问题 This question already has answers here : How to construct a relative path in Java from two absolute paths (or URLs)? (22 answers) Closed 3 years ago . I need to get the relative file path (relative to the program executable path) from a File object. What's the best way to do this? File offers only methods for the absolute path. Maybe getting execution path manually and then cut this path off from the absolute path to get a relative path? I am on Java 7, just in case java.nio has some helping

NodeJS - convert relative path to absolute

≯℡__Kan透↙ 提交于 2020-01-10 09:05:34
问题 In my File-system my working directory is here: C:\temp\a\b\c\d and under b\bb there's file: tmp.txt C:\temp\a\b\bb\tmp.txt If I want to go to this file from my working directory, I'll use this path: "../../bb/tmp.txt" In case the file is not exist I want to log the full path and tell the user: "The file C:\temp\a\b\bb\tmp.txt is not exist" . My question: I need some function that convert the relative path: "../../bb/tmp.txt" to absolute: "C:\temp\a\b\bb\tmp.txt" In my code it should be like

How to import files in python using sys.path.append?

你。 提交于 2020-01-09 19:16:14
问题 There are two directories on my desktop, DIR1 and DIR2 which contain the following files: DIR1: file1.py DIR2: file2.py myfile.txt The files contain the following: file1.py import sys sys.path.append('.') sys.path.append('../DIR2') import file2 file2.py import sys sys.path.append( '.' ) sys.path.append( '../DIR2' ) MY_FILE = "myfile.txt" myfile = open(MY_FILE) myfile.txt some text Now, there are two scenarios. The first works, the second gives an error. Scenario 1 I cd into DIR2 and run file2

How to import files in python using sys.path.append?

柔情痞子 提交于 2020-01-09 19:15:31
问题 There are two directories on my desktop, DIR1 and DIR2 which contain the following files: DIR1: file1.py DIR2: file2.py myfile.txt The files contain the following: file1.py import sys sys.path.append('.') sys.path.append('../DIR2') import file2 file2.py import sys sys.path.append( '.' ) sys.path.append( '../DIR2' ) MY_FILE = "myfile.txt" myfile = open(MY_FILE) myfile.txt some text Now, there are two scenarios. The first works, the second gives an error. Scenario 1 I cd into DIR2 and run file2

How to import files in python using sys.path.append?

断了今生、忘了曾经 提交于 2020-01-09 19:14:04
问题 There are two directories on my desktop, DIR1 and DIR2 which contain the following files: DIR1: file1.py DIR2: file2.py myfile.txt The files contain the following: file1.py import sys sys.path.append('.') sys.path.append('../DIR2') import file2 file2.py import sys sys.path.append( '.' ) sys.path.append( '../DIR2' ) MY_FILE = "myfile.txt" myfile = open(MY_FILE) myfile.txt some text Now, there are two scenarios. The first works, the second gives an error. Scenario 1 I cd into DIR2 and run file2

What does the dot-slash do to PHP include calls?

不羁岁月 提交于 2020-01-09 03:24:32
问题 A. What does this do? require ("./file.php"); B. in comparison to this? require ("file.php"); (Its not up-one-directory.. which would be) require ("../file.php"); 回答1: ./ is the current directory. It is largely the same as just file.php , but in many cases (this one included) it doesn't check any standard places PHP might look for a file, instead checking only the current directory. From the PHP documentation (notice the last sentence): Files for including are first looked for in each include

What does the dot-slash do to PHP include calls?

雨燕双飞 提交于 2020-01-09 03:24:07
问题 A. What does this do? require ("./file.php"); B. in comparison to this? require ("file.php"); (Its not up-one-directory.. which would be) require ("../file.php"); 回答1: ./ is the current directory. It is largely the same as just file.php , but in many cases (this one included) it doesn't check any standard places PHP might look for a file, instead checking only the current directory. From the PHP documentation (notice the last sentence): Files for including are first looked for in each include

How to force relative pathing with Struts 2.1 and Dojo?

自古美人都是妖i 提交于 2020-01-07 06:54:21
问题 I upgraded from Struts 2.0.6 to 2.1.6 and converted all my Ajax themes to plugins. Everything works except the pathing has changed from relative to absolute. For example, here is the rendered HTML before upgrade: <script type="text/javascript" src="../struts/simple/dojoRequire.js"></script> And here it is after upgrade: <script language="JavaScript" type="text/javascript" src="/myApp/struts/ajax/dojoRequire.js"></script> Somehow the absolute "/myApp" is getting used instead of the relative ".

How to get path relative to the working directory?

坚强是说给别人听的谎言 提交于 2020-01-07 04:59:06
问题 I have a script that recursively loops through all .txt files in the working directory and subdirectories and does something with that files. Now I would like to exclude all files in certain subdirectories that are listed in a exclude.txt file: @ECHO OFF SETLOCAL EnableDelayedExpansion for /r %%f in (*.txt) do ( CALL:processFile %%f %%~df%%~pf ) GOTO:EOF :processFile SET file_=%~1 SET path_=%~2 <- %%~df%%~pf is the full path :( find "!path_!" exclude.txt IF !ERRORLEVEL! EQU 1 ( REM do

Java's URL/URI doesn't resolve correctly links starting with ? (interrogation point)

妖精的绣舞 提交于 2020-01-06 23:42:17
问题 I'm trying to resolve a relative link that starts with a question mark ? using Java's URL or URI classes. HTML example: <a href="?test=xyz">Test XYZ</a> Code examples (from Scala REPL): import java.net._ scala> new URL(new URL("http://abc.com.br/index.php?hello=world"), "?test=xyz").toExternalForm() res30: String = http://abc.com.br/?test=xyz scala> (new URI("http://abc.com.br/index.php?hello=world")).resolve("?test=xyz").toString res31: java.net.URI = http://abc.com.br/?test=xyz The problem