Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
FILE HOSTS PREMIUM ACCOUNT
ALL FILE HOST PREMIUM ACCOUNTS
Zynga Slingo Trainer v5.12
iTunes Gift Card Generator V3.1 2012
Diablo 3 GOLD Coins FREE
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Empires & Allies Hack Cheat Trainer v5.4.1
Eve Onnline 60 Days Time Card Generator v2
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Better way to get content via jQuery $.get()
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
Pastable version of
get path of a File relative to a directory
<pre class='prettyprint' language='java'>public static String getRelativePath(File file, File relativeTo) throws IOException { /* * windows seems in some cases not to stop getParent() at 'c:\', which I * considered to be root. For that reason I had to tweak in the * following to 'ugly' lines: */ file = new File(file + File.separator + "89243jmsjigs45u9w43545lkhj7").getParentFile(); relativeTo = new File(relativeTo + File.separator + "984mvcxbsfgqoykj30487df556").getParentFile(); File origFile = file; File origRelativeTo = relativeTo; ArrayList<File> filePathStack = new ArrayList<File>(); ArrayList<File> relativeToPathStack = new ArrayList<File>(); // build the path stack info to compare it afterwards file = file.getCanonicalFile(); while (file != null) { filePathStack.add(0, file); file = file.getParentFile(); } relativeTo = relativeTo.getCanonicalFile(); while (relativeTo != null) { relativeToPathStack.add(0, relativeTo); relativeTo = relativeTo.getParentFile(); } // compare as long it goes int count = 0; file = filePathStack.get(count); relativeTo = relativeToPathStack.get(count); while ((count < filePathStack.size() - 1) && (count < relativeToPathStack.size() - 1) && file.equals(relativeTo)) { count++; file = filePathStack.get(count); relativeTo = relativeToPathStack.get(count); } if (file.equals(relativeTo)) count++; // up as far as necessary StringBuffer relString = new StringBuffer(); for (int i = count; i < relativeToPathStack.size(); i++) { relString.append(".." + File.separator); } // now back down to the file for (int i = count; i < filePathStack.size() - 1; i++) { relString.append(filePathStack.get(i).getName() + File.separator); } relString.append(filePathStack.get(filePathStack.size() - 1).getName()); // just to test File relFile = new File(origRelativeTo.getAbsolutePath() + File.separator + relString.toString()); if (!relFile.getCanonicalFile().equals(origFile.getCanonicalFile())) { throw new IOException("Failed to find relative path."); } return relString.toString(); }</pre> <a href="http://www.refactormycode.com/codes/443-get-path-of-a-file-relative-to-a-directory" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>