absolute-path

How to get the absolute path for a given relative path programmatically in Linux?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 20:38:45
How to get the absolute path for a given relative path programmatically in Linux? Incase of Windows we have the _fullpath() API. In other words, I mean what is analogous API to _fullpath of Windows in Linux? unwind As Paul mentioned, use realpath() . Please note though, that since many file systems in Linux support hard links , any given directory can have a number of different absolute paths. Check out the realpath function. #include <stdlib.h> #include <stdio.h> #include <linux/limits.h> int main() { char resolved_path[PATH_MAX]; realpath("../../", resolved_path); printf("\n%s\n",resolved

Do I need to pass the full path of a file in another directory to open()?

谁都会走 提交于 2019-11-27 19:13:22
I have a folder with ten files in it which I want to loop through. When I print out the name of the file my code works fine: import os indir = '/home/des/test' for root, dirs, filenames in os.walk(indir): for f in filenames: print(f) Which prints: 1 2 3 4 5 6 7 8 9 10 But if I try to open the file in the loop I get an IO error: import os indir = '/home/des/test' for root, dirs, filenames in os.walk(indir): for f in filenames: log = open(f, 'r') Traceback (most recent call last): File "/home/des/my_python_progs/loop_over_dir.py", line 6, in <module> log = open(f, 'r') IOError: [Errno 2] No such

Server Document Root Path in PHP [closed]

这一生的挚爱 提交于 2019-11-27 17:22:51
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I have a php code line like below $files = glob('myFolder/*'); I want to use absolute path to myFolder in above by using server document root, like below

Converting relative path into absolute path?

心已入冬 提交于 2019-11-27 12:16:49
I'm not sure if these paths are duplicates. Given the relative path, how do I determine absolute path using a shell script? Example: relative path: /x/y/../../a/b/z/../c/d absolute path: /a/b/c/d DVK From this source comes: #!/bin/bash # Assume parameter passed in is a relative path to a directory. # For brevity, we won't do argument type or length checking. ABS_PATH=`cd "$1"; pwd` # double quotes for paths that contain spaces etc... echo "Absolute path: $ABS_PATH" You can also do a Perl one-liner, e.g. using Cwd::abs_path The most reliable method I've come across in unix is readlink -f : $

How can I get MSBUILD to evaluate and print the full path when given a relative path?

馋奶兔 提交于 2019-11-27 11:25:22
问题 How can I get MSBuild to evaluate and print in a <Message /> task an absolute path given a relative path? Property Group <Source_Dir>..\..\..\Public\Server\</Source_Dir> <Program_Dir>c:\Program Files (x86)\Program\</Program_Dir> Task <Message Importance="low" Text="Copying '$(Source_Dir.FullPath)' to '$(Program_Dir)'" /> Output Copying '' to 'c:\Program Files (x86)\Program\' 回答1: In MSBuild 4.0 , the easiest way is the following: $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)

PHP absolute path to root

女生的网名这么多〃 提交于 2019-11-27 11:20:17
I can't believe PHP doesn't have an easy solution of this simple matter. ASP.NET has a ~ sign that cares of this issue and starts everything from root level. Here's my problem: localhost/MySite -->Admin -- Edit.php -->Class -- class.EditInfo.php -->Texts -- MyInfo.txt --ShowInfo.php Inside class.EditInfo.php I am accessing MyInfo.txt so I defined a relative path "../Texts/MyInfo.txt". Then I created an object of EditInfo in Admin/Edit.php and accessed Texts/MyInfo.txt it worked fine. But now I have to create an object of EditInfo in ShowInfo.php and access Texts/MyInfo.txt and here's the

PHP include absolute path

百般思念 提交于 2019-11-27 09:03:49
I have a variable on my site called $basePath which is set as: $basePath = '/Systems/dgw/'; I am using it on all my css, js and images tags as so (shortened for better visibility): <link href="<?php echo $basePath; ?>include/assets/css/bootstrap.min.css"> I have no problem with those includes and they work fine in wherever file and in whatever folder I am. I have a certain included page which has the following line: <img src="<?php echo $basePath; ?>images/new_logo.png" alt="logo"/> And the image shows just fine. The line after it states: <?php include($basePath.'include/assets/common

How to get the file-path of the currently executing javascript code

我与影子孤独终老i 提交于 2019-11-27 06:29:15
I'm trying to do something like a C #include "filename.c" , or PHP include(dirname(__FILE__)."filename.php") but in javascript. I know I can do this if I can get the URL a js file was loaded from (e.g. the URL given in the src attribute of the tag). Is there any way for the javascript to know that? Alternatively, is there any good way to load javascript dynamically from the same domain (without knowing the domain specifically)? For example, lets say we have two identical servers (QA and production) but they clearly have different URL domains. Is there a way to do something like include("myLib

Relative path to absolute path in C#?

☆樱花仙子☆ 提交于 2019-11-27 05:20:54
问题 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

python/zip: How to eliminate absolute path in zip archive if absolute paths for files are provided?

纵饮孤独 提交于 2019-11-27 03:48:53
I have two files in two different directories, one is '/home/test/first/first.pdf' , the other is '/home/text/second/second.pdf' . I use following code to compress them: import zipfile, StringIO buffer = StringIO.StringIO() first_path = '/home/test/first/first.pdf' second_path = '/home/text/second/second.pdf' zip = zipfile.ZipFile(buffer, 'w') zip.write(first_path) zip.write(second_path) zip.close() After I open the zip file that I created, I have a home folder in it, then there are two sub-folders in it, first and second , then the pdf files. I don't know how to include only two pdf files