Documentation Archive Developer
Search
PATH Documentation > WebObjects

Table of Contents

NSPathUtilities


Inherits from:
Object
Package:
com.webobjects.foundation


Class Description


This class provides static methods that are useful when working with paths. Specifically, it includes methods that extract particular path components ( lastPathComponent and pathExtension), modify paths ( stringByAppendingPathComponent, stringByAppendingPathExtension, stringByDeletingLastPathComponent, stringByDeletingPathExtension, and stringByStandardizingPath), and return special paths ( homeDirectory).

The NSPathUtilities class cannot be instantiated.




Method Types


Extracting path components
lastPathComponent
pathExtension
Manipulating paths
stringByAppendingPathComponent
stringByAppendingPathExtension
stringByDeletingLastPathComponent
stringByDeletingPathExtension
stringByNormalizingExistingPath
stringByStandardizingPath
Resolving special paths
homeDirectory
Deprecated methods
URLWithPath
fileExistsAtPath
pathIsAbsolute
pathIsEqualToString


Static Methods



fileExistsAtPath

public static boolean fileExistsAtPath(String aString)

Deprecated in the Java Foundation framework. Don't use this method. Use (new File(aString)).exists() instead.

homeDirectory

public static String homeDirectory()

Returns a string containing the home directory path for the user who executes the application.

lastPathComponent

public static String lastPathComponent(String aString)

Returns the last path component of aString. The following table illustrates the effect of lastPathComponent on a variety of different paths:
aString's Value String Returned
"/tmp/scratch.tiff" "scratch.tiff"
"/tmp/scratch" "scratch"
"/tmp/" "tmp"
"scratch" "scratch"
"/" "" (an empty string)



pathExtension

public static String pathExtension(String aString)

Interprets aString as a path, returning the aString's extension, if any (not including the extension divider). The following table illustrates the effect of pathExtension on a variety of different paths:
aString's Value String Returned
"/tmp/scratch.tiff" "tiff"
"/tmp/scratch" "" (an empty string)
"/tmp/" "" (an empty string)
"/tmp/scratch..tiff" "tiff"



pathIsAbsolute

public static boolean pathIsAbsolute(String aString)

Deprecated in the Java Foundation framework. Don't use this method. Use (new File(aString)).isAbsolute() instead.

pathIsEqualToString

public static boolean pathIsEqualToString( String string1, String string2)

Deprecated in the Java Foundation framework. Don't use this method. You should never have to invoke it.

stringByAppendingPathComponent

public static String stringByAppendingPathComponent( String string1, String string2)

Returns a string made by appending string1 with string2, preceded by if necessary by a path separator. The following table illustrates the effect of this method on a variety of different paths, assuming that string2 is supplied as "scratch.tiff":
string1's Value Resulting String
"/tmp" "/tmp/scratch.tiff"
"/tmp/" "/tmp/scratch.tiff"
"/" "/scratch.tiff"
"" (an empty string) "scratch.tiff"

See Also: stringByAppendingPathExtension, stringByDeletingLastPathComponent



stringByAppendingPathExtension

public static String stringByAppendingPathExtension( String string1, String string2)

Returns a string made by appending to string1 an extension separator followed by string2. Note that if string1 ends with one or more slashes ("/"), these slashes are deleted. The following table illustrates the effect of this method on a variety of different paths, assuming that string2 is supplied as "tiff":
string1's Value Resulting String
"/tmp/scratch.old" "/tmp/scratch.old.tiff"
"/tmp/scratch." "/tmp/scratch..tiff"
"/tmp/" "/tmp.tiff"
"scratch" "scratch.tiff"



stringByDeletingLastPathComponent

public static String stringByDeletingLastPathComponent(String aString)

Returns a string made by deleting the last path component from aString, along with any final path separator. If aString represents the root path, however, it's returned unaltered. The following table illustrates the effect of this method on a variety of different paths:
aString's Value Resulting String
"/tmp/scratch.tiff" "/tmp"
"/tmp/lock/" "/tmp"
"/tmp/" "/"
"/tmp" "/"
"/" "/"
"scratch.tiff" "" (an empty string)

See Also: stringByDeletingPathExtension, stringByAppendingPathComponent



stringByDeletingPathExtension

public static String stringByDeletingPathExtension(String aString)

Returns a string made by deleting the extension (if any, and only the last) from aString. Strips any trailing path separator before checking for an extension. If aString represents the root path, however, it's returned unaltered. The following table illustrates the effect of this method on a variety of different paths:
aString's Value Resulting String
"/tmp/scratch.tiff" "/tmp/scratch"
"/tmp/" "/tmp"
"scratch.bundle/" "scratch"
"scratch..tiff" "scratch."
".tiff" "" (an empty string)
"/" "/"

See Also: pathExtension, stringByDeletingLastPathComponent



stringByNormalizingExistingPath

public static String stringByNormalizingExistingPath(String aString)

Returns a string containing the "normalized" path for an existing file with path aString. If the file does not exist, this method returns null. The normalized path is always absolute and corresponds to the canonical path returned by the java.io.File.getCanonicalPath method. See Sun's documentation for this method for more information.

See Also: stringByStandardizingPath



stringByStandardizingPath

public static String stringByStandardizingPath(String aString)

Returns a string made by resolving various elements of aString. If the path contains tilde (~), inserts the home directory path in its place. If the path contains the parent directory marker (..) removes the previous path component from the path. If the parent directory marker is at the beginning of aString, throws an IllegalArgumentException. The following table illustrates the effect of this method on a variety of different paths assuming that the home directory is "/Local/Users/guest":
aString's Value Resulting String
"~/scratch.tiff" "/Local/Users/guest/scratch.tiff"
"~" "/Local/Users/guest"
"~/.." "/Local/Users/"
"guest/../john/scratch.tiff" "john/scratch.tiff"
"../scratch.tiff" throws IllegalArgumentException



URLWithPath

public static java.net.URL URLWithPath(String aString)

Deprecated in the Java Foundation framework. Don't use this method. Use new URL("file://" + aString) instead.

© 2001 Apple Computer, Inc. (Last Published April 17, 2001)


Table of Contents