Java tutorial
//package com.java2s; public class Main { public static String getDirectory(String path) { String osName = System.getProperty("os.name"); // test(osName); if (osName.contains("Win")) { path = path.substring(0, path.lastIndexOf('\\') + 1); } else { path = path.substring(0, path.lastIndexOf('/') + 1); } return path; } }