// NAnt - A .NET build tool
// Copyright (C) 2001-2003 Gerry Shaw
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Ian Maclean (imaclean@gmail.com)
// Jaroslaw Kowalski (jkowalski@users.sourceforge.net)
using System;
using System.IO;
using System.Collections;
using System.Reflection;
using System.Globalization;
using NAnt.Core;
using NAnt.Core.Attributes;
using NAnt.Core.Types;
using NAnt.Core.Util;
namespace NAnt.Core.Functions {
[FunctionSet("path", "Path")]
public class PathFunctions : FunctionSetBase {
#region Public Instance Constructors
public PathFunctions(Project project, PropertyDictionary properties) : base(project, properties) {
}
#endregion Public Instance Constructors
#region Public Instance Methods
///
/// Returns the fully qualified path.
///
/// The file or directory for which to obtain absolute path information.
///
/// A string containing the fully qualified location of ,
/// such as "C:\MyFile.txt".
///
/// is a zero-length string, contains only white space, or contains one or more invalid characters.
/// contains a colon (":").
/// The specified path, file name, or both exceed the system-defined maximum length.
[Function("get-full-path")]
public string GetFullPath(string path) {
return Project.GetFullPath(path);
}
#endregion Public Instance Methods
#region Public Static Methods
///
/// Combines two paths.
///
/// first path
/// second path
///
/// A string containing the combined paths. If one of the specified paths
/// is a zero-length string, this method returns the other path. If
/// contains an absolute path, this method
/// returns .
///
/// or contain one or more invalid characters.
[Function("combine")]
public static string Combine(string path1, string path2) {
return Path.Combine(path1, path2);
}
///
/// Changes the extension of the path string.
///
/// The path information to modify. The path cannot contain any of the characters
/// defined in InvalidPathChars.
/// The new extension (with a leading period). Specify a null reference
/// to remove an existing extension from .
///
///
/// A string containing the modified path information.
///
///
/// On Windows-based desktop platforms, if is
/// an empty , the path information is returned
/// unmodified. If has no extension, the returned
/// path contains
/// appended to the end of .
///
///
///
/// For more information see the documentation.
///
/// contains one or more invalid characters.
[Function("change-extension")]
public static string ChangeExtension(string path, string extension) {
return Path.ChangeExtension(path, extension);
}
///
/// Returns the directory information for the specified path string.
///
/// The path of a file or directory.
///
/// A containing directory information for
/// , or an empty if
/// denotes a root directory, or does not
/// contain directory information.
///
/// contains invalid characters, is empty, or contains only white spaces.
[Function("get-directory-name")]
public static string GetDirectoryName(string path) {
string dirName = Path.GetDirectoryName(path);
return StringUtils.ConvertNullToEmpty(dirName);
}
///
/// Returns the extension for the specified path string.
///
/// The path string from which to get the extension.
///
/// A containing the extension of the specified
/// (including the "."), or an empty
/// if does not have
/// extension information.
///
/// contains one or more invalid characters.
[Function("get-extension")]
public static string GetExtension(string path) {
return Path.GetExtension(path);
}
///
/// Returns the filename for the specified path string.
///
/// The path string from which to obtain the file name and extension.
///
///
/// A consisting of the characters after the last
/// directory character in path.
///
///
/// If the last character of is a directory or
/// volume separator character, an empty is returned.
///
///
/// contains one or more invalid characters.
[Function("get-file-name")]
public static string GetFileName(string path) {
return Path.GetFileName(path);
}
///
/// Returns the filename without extension for the specified path string.
///
/// The path of the file.
///
/// A containing the returned
/// by , minus the last period (.) and all
/// characters following it.
///
/// contains one or more invalid characters.
[Function("get-file-name-without-extension")]
public static string GetFileNameWithoutExtension(string path) {
return Path.GetFileNameWithoutExtension(path);
}
///
/// Gets the root directory of the specified path.
///
/// The path from which to obtain root directory information.
///
/// A containing the root directory of
/// , such as "C:\", or an empty
/// if does not contain root directory information.
///
/// contains invalid characters, or is empty.
[Function("get-path-root")]
public static string GetPathRoot(string path) {
string pathRoot = Path.GetPathRoot(path);
return StringUtils.ConvertNullToEmpty(pathRoot);
}
///
/// Returns a uniquely named zero-byte temporary file on disk and returns the full path to that file.
///
///
/// A containing the name of the temporary file.
///
[Function("get-temp-file-name")]
public static string GetTempFileName() {
return Path.GetTempFileName();
}
///
/// Gets the path to the temporary directory.
///
///
/// A containing the path information of a
/// temporary directory.
///
[Function("get-temp-path")]
public static string GetTempPath() {
return Path.GetTempPath();
}
///
/// Determines whether a path string includes an extension.
///
/// The path to search for an extension.
///
/// . if the characters that follow the last
/// directory separator or volume separator in the
/// include a period (.) followed by one or more characters;
/// otherwise, .
///
/// contains one or more invalid characters.
[Function("has-extension")]
public static bool HasExtension(string path) {
return Path.HasExtension(path);
}
///
/// Determines whether a path string is absolute.
///
/// The path to test.
///
/// if path contains an absolute ;
/// otherwise, .
///
/// contains one or more invalid characters.
[Function("is-path-rooted")]
public static bool IsPathRooted(string path) {
return Path.IsPathRooted(path);
}
#endregion Public Static Methods
}
}