path

How to get full path of a file?

假如想象 提交于 2019-12-28 03:15:07
问题 Is there an easy way I can print the full path of file.txt ? file.txt = /nfs/an/disks/jj/home/dir/file.txt The <command> dir> <command> file.txt should print /nfs/an/disks/jj/home/dir/file.txt 回答1: Use readlink: readlink -f file.txt 回答2: I suppose you are using Linux. I found a utility called realpath in coreutils 8.15. realpath file.txt /data/ail_data/transformed_binaries/coreutils/test_folder_realpath/file.txt As per @styrofoam-fly and @arch-standton comments, realpath alone doesn't check

How to replace a path with another path in sed?

强颜欢笑 提交于 2019-12-28 02:57:33
问题 I have a csh script (although I can change languages if it has any relevance) where I have to: sed s/AAA/BBB/ file The problem is that AAA and BBB are paths, and so contain '/'. AAA is fixed, so I can say: sed s/\\\/A\\\/A\\\A/BBB/ file However, BBB is based on variables, including $PWD. How do I escape the '/' in $PWD? OR is there some other way I should be doing this entirely? 回答1: sed can use any separator instead of / in the s command. Just use something that is not encountered in your

Best way to determine if two path reference to same file in Windows?

半世苍凉 提交于 2019-12-28 02:11:28
问题 How would I compare 2 strings to determine if they refer to the same path in Win32 using C/C++? While this will handle a lot of cases it misses some things: _tcsicmp(szPath1, szPath2) == 0 For example: forward slashes / backslashes relative / absolute paths. [Edit] Title changed to match an existing C# question. 回答1: Open both files with CreateFile , call GetFileInformationByHandle for both, and compare dwVolumeSerialNumber , nFileIndexLow , nFileIndexHigh . If all three are equal they both

Conversion between absolute and relative paths in Delphi

可紊 提交于 2019-12-28 01:54:27
问题 Are there standard functions to perform absolute <--> relative path conversion in Delphi? For example: 'Base' path is 'C:\Projects\Project1\' Relative path is '..\Shared\somefile.pas' Absolute path is 'C:\Projects\Shared\somefile.pas' I am looking for something like this: function AbsToRel(const AbsPath, BasePath: string): string; // '..\Shared\somefile.pas' = // AbsToRel('C:\Projects\Shared\somefile.pas', 'C:\Projects\Project1\') function RelToAbs(const RelPath, BasePath: string): string; //

How to configure Atom to run Python3 scripts?

血红的双手。 提交于 2019-12-27 17:41:07
问题 In my terminal, I type $ which python3 , outputting /opt/local/bin/python3 I would like to configure Atom to run Python3 scripts. In my Atom Config, I have runner: python: "/opt/local/bin/python3" However, if I run the following script in some script named filename.py , import sys print(sys.version) I get the following output: 2.7.11 (default, Feb 18 2016, 22:00:44) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] How exactly does one set up the PATH for Python3.x scripts to run

Detect if user's path has a specific directory in it

给你一囗甜甜゛ 提交于 2019-12-27 17:29:46
问题 With /bin/bash , how would I detect if a user has a specific directory in their $PATH variable? For example if [ -p "$HOME/bin" ]; then echo "Your path is missing ~/bin, you might want to add it." else echo "Your path is correctly set" fi 回答1: Something really simple and naive: echo "$PATH"|grep -q whatever && echo "found it" Where whatever is what you are searching for. Instead of && you can put $? into a variable or use a proper if statement. Limitations include: The above will match

Python: Platform independent way to modify PATH environment variable

女生的网名这么多〃 提交于 2019-12-27 16:44:47
问题 Is there a way to modify the PATH environment variable in a platform independent way using python? Something similar to os.path.join() ? 回答1: You should be able to modify os.environ . Since os.pathsep is the character to separate different paths, you should use this to append each new path: os.environ["PATH"] += os.pathsep + path or, if there are several paths to add in a list: os.environ["PATH"] += os.pathsep + os.pathsep.join(pathlist) As you mentioned, os.path.join can also be used for

Path.Combine absolute with relative path strings

痴心易碎 提交于 2019-12-27 12:20:56
问题 I'm trying to join a Windows path with a relative path using Path.Combine. However, Path.Combine(@"C:\blah",@"..\bling") returns C:\blah\..\bling instead of C:\bling\ . Does anyone know how to accomplish this without writing my own relative path resolver (which shouldn't be too hard)? 回答1: What Works: string relativePath = "..\\bling.txt"; string baseDirectory = "C:\\blah\\"; string absolutePath = Path.GetFullPath(baseDirectory + relativePath); (result: absolutePath="C:\bling.txt") What doesn

Path.Combine absolute with relative path strings

非 Y 不嫁゛ 提交于 2019-12-27 12:20:12
问题 I'm trying to join a Windows path with a relative path using Path.Combine. However, Path.Combine(@"C:\blah",@"..\bling") returns C:\blah\..\bling instead of C:\bling\ . Does anyone know how to accomplish this without writing my own relative path resolver (which shouldn't be too hard)? 回答1: What Works: string relativePath = "..\\bling.txt"; string baseDirectory = "C:\\blah\\"; string absolutePath = Path.GetFullPath(baseDirectory + relativePath); (result: absolutePath="C:\bling.txt") What doesn

Getting the folder name from a path

不打扰是莪最后的温柔 提交于 2019-12-27 11:02:11
问题 string path = "C:/folder1/folder2/file.txt"; What objects or methods could I use that would give me a result of folder2 ? 回答1: I would probably use something like: string path = "C:/folder1/folder2/file.txt"; string lastFolderName = Path.GetFileName( Path.GetDirectoryName( path ) ); The inner call to GetDirectoryName will return the full path, while the outer call to GetFileName() will return the last path component - which will be the folder name. This approach works whether or not the path