All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.jhonsapp.repository.util.PathUtil Maven / Gradle / Ivy

Go to download

Repository is a project created by Jhonathan Camacho to facilitate the file management in local and remote repositories.

There is a newer version: 1.0.12
Show newest version
package br.com.jhonsapp.repository.util;

import java.io.File;

/**
 * This class format the file path.
 * 
 * @author Jhonathan Camacho
 *
 */
public class PathUtil {

	/**
	 * Format the path in this pattern. Ex: folder1/folder2/folder3/
	 * 
	 * @param path
	 *            the directory to be formatted.
	 * 
	 * @return the formatted folder.
	 */
	public static final String pathFormat(String path) {

		path = path.replaceAll("[/]", File.separator);

		if (path.charAt(0) == '/')
			path = path.substring(1);

		if (path.charAt(path.length() - 1) != '/')
			path = path + File.separator;

		return path;
	}
	
	/**
	 * Gets the id of a string that contains the folder concatenated with the identifier.
	 * 
	 * @param fullPath
	 *            string containing the folder concatenated with the identifier.
	 * 
	 * @return the identifier.
	 */
	public static final String getId(String fullPath) {

		String values[] = fullPath.split("[/]");

		return values[values.length - 1];
	}
	
	/**
	 * Gets the folder of a string that contains the folder concatenated with the identifier.
	 * 
	 * @param fullPath
	 *            string containing the folder concatenated with the identifier.
	 * 
	 * @return the folders.
	 */
	public static final String getFolder(String fullPath) {

		String values[] = fullPath.substring(1).split("[/]");

		String folder = "";

		for (int i = 0; i < values.length - 1; i++) {
			folder = folder + values[i] + File.pathSeparator;
		}

		return pathFormat(folder);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy