absolute-path

Expand a possible relative path in bash

纵然是瞬间 提交于 2019-11-28 17:18:56
问题 As arguments to my script there are some file paths. Those can, of course, be relative (or contain ~). But for the functions I've written I need paths that are absolute, but do not have their symlinks resolved. Is there any function for this? 回答1: MY_PATH=$(readlink -f $YOUR_ARG) will resolve relative paths like "./" and "../" Consider this as well (source): #!/bin/bash dir_resolve() { cd "$1" 2>/dev/null || return $? # cd to desired directory; if fail, quell any error messages but return

Get absolute paths of all files in a directory

半城伤御伤魂 提交于 2019-11-28 16:49:29
How do I get the absolute paths of all the files in a directory that could have many sub-folders in Python? I know os.walk() recursively gives me a list of directories and files, but that doesn't seem to get me what I want. os.path.abspath makes sure a path is absolute. Use the following helper function: import os def absoluteFilePaths(directory): for dirpath,_,filenames in os.walk(directory): for f in filenames: yield os.path.abspath(os.path.join(dirpath, f)) If the argument given to os.walk is absolute, then the root dir names yielded during iteration will also be absolute. So, you only need

Absolute Path of Project's folder in Java

谁说我不能喝 提交于 2019-11-28 09:31:06
Lots of confusion in this topic. Several Questions have been asked. Things still seem unclear. ClassLoader, Absolute File Paths etc etc Suppose I have a project directory structure as, MyProject-- --dist --lib --src --test I have a resource say "txtfile.txt" in "lib/txt" directory. I want to access it in a system independent way. I need the absolute path of the project. So I can code the path as abspath+"/lib/Dictionary/txtfile.txt" Suppose I do this java.io.File file = new java.io.File(""); //Dummy file String abspath=file.getAbsolutePath(); I get the current working directory which is not

PHP: Require path does not work for cron job?

感情迁移 提交于 2019-11-28 08:59:47
I have a cron job that needs to include this file: require '../includes/common.php'; however, when it is run via the cron job (and not my local testing), the relative path does not work. the cron job runs the following file (on the live server): /home/username123/public_html/cron/mycronjob.php and here's the error: Fatal error: require(): Failed opening required '../includes/common.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/username123/public_html/cron/mycronjob.php on line 2 using the same absolute format as the cron job, common.php would be located at /home/username123

Relative instead of Absolute paths in Excel VBA

青春壹個敷衍的年華 提交于 2019-11-28 05:41:47
I have written an Excel VBA macro which imports data from a HTML file (stored locally) before performing calculations on the data. At the moment the HTML file is referred to with an absolute path: Workbooks.Open FileName:="C:\Documents and Settings\Senior Caterer\My Documents\Endurance Calculation\TRICATEndurance Summary.html" However I want to use a relative path to refer to it as opposed to absolute (this is because I want to distribute the spreadsheet to colleagues who might not use the same folder structure). As the html file and the excel spreadsheet sit in the same folder I would not

Python won't exit when called with absolute path from cron or subshell

不羁的心 提交于 2019-11-28 05:32:08
问题 I have some python scripts that run via cron, and they no longer exit correctly when the script is called with an absolute path. They will hang until the process is terminated. I believe it happened after I moved /var and /home to a different partition. I checked into the environment variables and couldn't see anything obviously wrong, this happens either when run with cron or a bash subshell, but not when run directly. If I run it as a subshell it hangs until I kill it (ctrl-c) and then

Relative path to absolute path in C#?

拥有回忆 提交于 2019-11-28 04:27:09
I have xml files that contain href file paths to images (e.g. "....\images\image.jpg"). The hrefs contain relative paths. Now, I need to extract the hrefs to the images and turn them into absolute paths in the file system. I know about the GetFullPath method, but I tried it and it only seems to work from the CurrentDirectory set, which appears to be C: so I don't see how I could use that. And still, I have the absolute path of the file containing the hrefs, and the href relative paths, so since it is a simple task for me to count back the number of "....\" parts based on the absolute path of

When to use Absolute Path vs Relative Path in Python

∥☆過路亽.° 提交于 2019-11-28 04:22:55
问题 For reference. The absolute path is the full path to some place on your computer. The relative path is the path to some file with respect to your current working directory (PWD). For example: Absolute path: C:/users/admin/docs/stuff.txt If my PWD is C:/users/admin/ , then the relative path to stuff.txt would be: docs/stuff.txt Note, PWD + relative path = absolute path. Cool, awesome. Now, I wrote some scripts which check if a file exists. os.chdir("C:/users/admin/docs") os.path.exists("stuff

How to get absolute path of file or directory, that does *not* exist?

眉间皱痕 提交于 2019-11-28 02:44:38
问题 How can I determine the absolute path of a file or directory from a given relative path in C/C++ on GNU/Linux? I know about realpath() , but it does not work on non-existing files. Let's say the user enters ../non-existant-directory/file.txt , and the programs working directory is /home/user/ . What I need is a function that returns /home/non-existant-directory/file.txt . I need this function to check if a given path is in a certain subdirectory or not. 回答1: Try realpath . If it fails, start

Relative path or absolute path and how to set up in PHP

99封情书 提交于 2019-11-28 02:07:15
问题 I have a site that I am working on and I am trying to go to the main directory of the site and I do not know how to set that up. What I am trying to do is include _inc/config.php through /_inc/config.php instead of having to use ../_inc/config.php Any ideas how to add this? 回答1: Generally speaking, there are two different problems to solve when dealing with paths: Filesystem paths (which you need to use to include a file) URL paths (which you need to use when building a URL internal to your