Path.GetDirectoryName 获取目录名字

static function GetDirectoryName (path : string) : string

Description描述

Returns the directory name component of the specified path string.

返回指定路径字符串组件的目录名字。

The string returned by this method consists of all characters between the first and last DirectorySeparatorChar or AltDirectorySeparatorChar character in the path. The first separator character is included, but the last separator character is not included in the returned string.

此方法返回路径的字符串包含的所有字符在首个和最后一个DirectorySeparatorCharAltDirectorySeparatorChar字符之间。首个分割字符包含在内,但是最后一个分隔符不包含在返回的字符串。

using System.IO;
using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Start() {
		Debug.Log(Path.GetDirectoryName("/Path/To/A/File/foo.txt"));
	}
}
//Remember to import IO to make Path work.
//记得导入IO,是路径正常工作

import System.IO;

function Start () {
	//This will print "/Path/To/A/File".
	//这会打印"/Path/To/A/File"
	Debug.Log(Path.GetDirectoryName("/Path/To/A/File/foo.txt"));
}
Page last updated: 2011-3-10