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"));
}
最后修改:2011年3月10日 Thursday 20:34

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。