filepath

Check if two file paths resolve to the same file

筅森魡賤 提交于 2019-12-24 01:53:53
问题 Say I have three file paths: setwd("C:/superlongdirname") files <- c("C:/superlongdirname/myfile.txt", "C:\\SUPERL~1\\myfile.txt", "./myfile.txt") These all point to the same file. How, given multiple references to the same file, can I check that they are indeed referring to the same file within R? 回答1: Use the full version of the filepaths and compare: normalizePath(files[1]) == normalizePath(files[2]) 来源: https://stackoverflow.com/questions/39095537/check-if-two-file-paths-resolve-to-the

Getting the path to the directory of a given class file

人走茶凉 提交于 2019-12-23 21:49:29
问题 I was confronted with code which tries to read some configuration files from the same directory where the .class file for the class itself is: File[] configFiles = new File( this.getClass().getResource(".").getPath()).listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".xml"); } }); Apparently this works in some cases (when running the code inside Resin, perhaps), but for me, running Tomcat, it simply fails with NPE, because getClass()

Get JRuby jar path

…衆ロ難τιáo~ 提交于 2019-12-23 20:26:54
问题 Similar to this question, I'd like to know how to get the current jar file's path. But unlike the other question, I want to know the jar 's path, not the path of the current file inside the jar. For example, say I had a jruby jar at "/Users/MyUser/Jars/foo.jar" and inside was a compiled ruby file at "foo.jar/java/style/class/path.class". How could class.path get the path "/Users/MyUser/Jars/foo.jar"? I also saw a way to do it in Java, but I just don't know how to translate it... 回答1: I have

Use shell symbols in directory path

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 16:46:14
问题 I want to open a file with my program, and I want to use shell symbols to make it easier for me to locate the file. Is there an easy way to have the shell expand out my file path before I use it on runtime. I'm looking for a function that does this. ~/.foo.bar -> /home/someuser/.foo.bar Is there some easy way to have the shell preprocess the paths to files before opening the file? 回答1: You can use wordexp: #include <wordexp.h> std::string wordexp(std::string var, int flags = 0) { wordexp_t p;

Use multiple file extensions for glob to find files

社会主义新天地 提交于 2019-12-23 13:15:23
问题 I am using glob to list out all my python files in the home directory by this line of code. I want to find all .json files too along with py files, but I couldn't found any to scan for multiple file types in one line code. for file in glob.glob('/home/mohan/**/*.py', recursive=True): print(file) 回答1: You could use os.walk, which looks in subdirectories as well. import os for root, dirs, files in os.walk("path/to/directory"): for file in files: if file.endswith((".py", ".json")): # The arg can

how can we know that an Android Application is closed?

给你一囗甜甜゛ 提交于 2019-12-22 17:53:08
问题 I am developing an Android Application to download an .mp3 file from server. When downloading is finished the file will be stored in a DIFFRENT EXTENSION (.srt) . and when the user clicked on the play button the file's EXTENSION will be changed back into .mp3 and play And when the user exit's the Application the file will go back to the (.srt) format. Everything works Fine . But now if the user close the application without pressing BackKey the extension will be the same. my code is public

Java Properties, getting file path

我与影子孤独终老i 提交于 2019-12-22 05:47:12
问题 logpath = LoggerUtils.getProperties().getProperty("log.path"); System.out.println("logpath: " + logpath); The above code returns: logpath: C:UsersMauriceDesktopLogs In the properties file is: log.path C:\Users\Maurice\Desktop\Logs How do I retain the file separators? I want this to work on Linux as well and not just Windows. 回答1: Actually, you need to put this in the property file: log.path C:\\Users\\Maurice\\Desktop\\Logs See this: http://docs.oracle.com/javase/6/docs/api/java/util

Add unique suffix to file name

a 夏天 提交于 2019-12-21 18:32:27
问题 Sometimes I need to ensure I'm not overwriting an existing file when saving some data, and I'd like to use a function that appends a suffix similar to how a browser does it - if dir/file.txt exists, it becomes dir/file (1).txt . 回答1: This is an implementation I've made, that uses Qt functions: // Adds a unique suffix to a file name so no existing file has the same file // name. Can be used to avoid overwriting existing files. Works for both // files/directories, and both relative/absolute

Transformer library that comes with Java converts spaces in file paths to %20

纵然是瞬间 提交于 2019-12-21 12:40:16
问题 Here is a test application that writes out XML Files. Why are the spaces in my path being converted to %20 ? public class XmlTest { public static void main(String[] args) { String filename = "C:\\New Folder\\test.xml"; try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer

Drive letter from URI type file path in C#

﹥>﹥吖頭↗ 提交于 2019-12-21 08:18:08
问题 What is the easiest way to get the drive letter from a URI type file path such as file:///D:/Directory/File.txt I know I can do (path here is a string containing the text above) path = path.Replace(@"file:///", String.Empty); path = System.IO.Path.GetPathRoot(path); but it feels a bit clumsy. Is there a way to do it without using String.Replace or similar? 回答1: var uri = new Uri("file:///D:/Directory/File.txt"); if (uri.IsFile) { DriveInfo di = new DriveInfo(uri.LocalPath); var driveName = di