GetFilePath Method  
 

Parses a file URL and returns the full path of a local file or network share.

Syntax

FilePath = object.GetFilePath( FileUrl )

Parameters

FileUrl
A string which specifies the file URL. It is not necessary for the file URL to reference a file which exists. The string must begin with the file:// scheme and use valid URL encoding for special characters.

Return Value

If the method is successful it returns a string which contains the full path to the file specified in the URL. If the method fails, it will return an empty string.

Remarks

The GetFilePath method parses a file URL and returns the equivalent absolute Windows path. This includes support for URLs that reference local files, mapped drives, and UNC network shares. The returned path is normalized to remove extraneous path delimiters and redundant components (such as . or .. directory references) and will ensure it adheres to the standard Windows path format. The file name returned by this method is always an absolute path.

URL encoding ensures interoperability with other platforms and allows safe transport over networks using protocols which may not support 8-bit characters. If the file URL contains encoded UTF-8 characters they will be automatically decoded. If the file URL contains an invalid UTF-8 encoding sequence, this can cause the method to fail.

This method does not require the file to exist and will not check access permissions. It is solely concerned with converting a URL to a Windows-compatible file path. If validation is required, it must be performed separately after calling this method. The method will preserve any mixed-case characters in the file path.

It is important to note that file URLs always reference absolute paths. Some older browsers and early versions of the Java runtime supported file URLs with relative paths by omitting the authority portion of the URL; however, this method explicitly prohibits this usage because relative paths may not be deterministic. The current working directory is stored as a global value for each process, and the use of a file URL with a relative path can potentially cause unpredictable behavior.

The GetFileUrl method can be used to convert a Windows file path to a standard a file URL.

See Also