relative-path

When to use Absolute Path vs Relative Path in Python

吃可爱长大的小学妹 提交于 2019-11-29 10:50:54
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.txt") This returns TRUE if stuff.txt exists and it works . Now, instead if I write, os.path.exists("C:

How to find relative path given two absolute paths?

吃可爱长大的小学妹 提交于 2019-11-29 10:45:21
Given two absolute paths, e.g. /a/path/to/a /a/path/to/somewhere/else How can I get a relative path from one to the other, ../a ? In a sense, the opposite of what realpath does. Thomas Dickey I answered a similar question here: Resolving a relative path without referencing the current directory on Windows . There is no standard function for this. There is a function in vi-like-emacs for this purpose. A quick check of apropos relative shows me few other programs which likely implement this: revpath for example). It could be done as a string-manipulation (no need to compute working directories):

Xaml - Bitmap UriSource - absolute path works, relative path does not, why?

故事扮演 提交于 2019-11-29 10:31:23
I'm, a WPF & Xaml-noob, for console applications it has worked for me to simply give the relative path to the executable to access a file. It doesn't seem to work in xaml for me. (code at the bottom) Absolute path works perfectly. Is it possible in XAML in a WPF-application to access a file by simply using a relative path to the directory of your executable as a valid UriSource? If yes how and if not why not? I found the following question, where they were talking about adding the file via Visual Studio's "Add existing item", so it seems like a different issue. How can I set the WPF

R: source() and path to source files

爱⌒轻易说出口 提交于 2019-11-29 10:00:25
问题 There must be something that I don't understand about the source() command in R. I'm still new to it, but I cannot for the life of me understand how it gets its directories from! My problem is this: I have a wrapper script, wrapper.R , and a source file containing some functions, functions.R . Both of these are in the same directory. If I call source('functions.R') inside the wrapper script, while standing inside the directory where both files are located, everything is fine. However, I want

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

别来无恙 提交于 2019-11-29 09:18:41
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. Try realpath . If it fails, start removing path components from the end one at a time and retrying realpath until it succeeds. Then append the

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

走远了吗. 提交于 2019-11-29 08:34:49
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? 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 application) These are two different beasts. Filesystem paths If your application has a single point of entry

OpenXML spreadsheet created in .NET won't open in iPad

江枫思渺然 提交于 2019-11-29 04:47:55
I am trying to generate a spreadsheet in .NET which will be opened by my manager on his iPad when he's out of the office. The spreadsheet opens fine on a Windows PC, but when trying to open on the iPad it says "An error occurred while reading the document" (so useful!) By using the "Compare" feature on the OpenXML SDK Productivity tool with a document that does open on the iPad, and by doing some manual editing of the faulty document's XML files in notepad I have narrowed it down to the file xl/_rels/workbook.xml.rels which stores the relationships of the parts in the workbook. This is the

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

僤鯓⒐⒋嵵緔 提交于 2019-11-29 00:03:24
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.py and it runs no problem. Scenario 2 I cd into DIR1 and run file1.py and it throws an error:

Java- relative path of text file in main?

别说谁变了你拦得住时间么 提交于 2019-11-28 21:35:37
I was wondering how to specifiy a relative path name to a text file that is stored in my src folder of a java project. I would like to store a string with the path of this text file. For example if I had example.txt located in the src folder of my java project how would I go about finding its relative path? I am also doing this in my main so I'm having trouble using .getResource(). How would I do this? Thanks. My files path is as followed from the properties in eclipse /MyProject/src/data.txt I've tried: String path = "/MyProject/src/data.txt"; But that doesn't work? If you are using eclipse,

Info.plist Utility Error: “Info.plist couldn't be opened because there is no such file”

感情迁移 提交于 2019-11-28 20:45:36
问题 I'm running into what seems to be common error, in that Xcode can't seem to find my 'Info.plist' file. I've checked the answers to these two StackOverflow questions (Could not read from Info.plist and Objective C/Xcode error: The file “Info.plist” couldn’t be opened because there is no such file)...I am using a relative path, and the plist file is in the correct absolute location. The type and location are correct as shown in the image below: My biggest concern is that this is now happening