File path issues in R using Windows (“Hex digits in character string” error)
replace all the \ with \\. it’s trying to escape the next character in this case the U so to insert a \ you need to insert an escaped \ which is \\
replace all the \ with \\. it’s trying to escape the next character in this case the U so to insert a \ you need to insert an escaped \ which is \\
Let File do the work of parsing and maintaining paths. As you want to display the files in a JTree, you might as well create a corresponding TreeModel such as FileTreeModel, cited here. Because it implements TreeModel, it can “be set as a JTree‘s model and then you’d have a plain old standard JTree.” You … Read more
Try; String path = new File(“.”).getCanonicalPath();
Add this class in your project ImageFilePath.java import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.ContentUris; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.os.Environment; import android.provider.DocumentsContract; import android.provider.MediaStore; //import android.provider.<span id=”IL_AD11″ class=”IL_AD”>MediaStore</span>; @SuppressLint(“NewApi”) @TargetApi(Build.VERSION_CODES.KITKAT) public class ImageFilePath { /** * Method for return file path of Gallery image * * @param context * @param uri * … Read more
Look at the System.IO.Directory class and the static method GetFiles. It has an overload that accepts a path and a search pattern. Example: string[] files = System.IO.Directory.GetFiles(path, “*.txt”);
The following code snippet will do this for you: final File f = new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath()); replace MyClass with your main class The resulting File object f represents the .jar file that was executed. You can use this object to get the parent to find the directory that the .jar is in.
A long read, but worth reading if you are in this domain: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx Extract: The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value … Read more
Portable Write filepath manipulations once and it works across many different platforms, for free. The delimiting character is abstracted away, making your job easier. Smart You no longer need to worry if that directory path had a trailing slash or not. os.path.join will add it if it needs to. Clear Using os.path.join makes it obvious … Read more
In R, you’ve to escape the \ with \\ So, your path should be: x <- “C:\\Users\\jd\\Documents\\folder\\file.txt” To get that, you can do: x <- readline() then, at the prompt, paste your unmodified path (CTRL+V then ENTER) Finally, to change \\ to / everywhere, you could use gsub, once again by escaping the \, but … Read more
just use File.getName() File f = new File(“C:\\Hello\\AnotherFolder\\The File Name.PDF”); System.out.println(f.getName()); using String methods: File f = new File(“C:\\Hello\\AnotherFolder\\The File Name.PDF”); System.out.println(f.getAbsolutePath().substring(f.getAbsolutePath().lastIndexOf(“\\”)+1));