在不使用GetParent()的情况下修剪最后一个目录/文件夹

时间:2014-01-31 20:26:36

标签: c# iphone filesystems

我试图模仿“cd ..”的作用,但不使用Getparent()。

输入:/ var / mobile / Documents /

实际输出:/ var / mobile / Documents /

所需的输出:/ var / mobile /

    public ArrayList JumpUpDirectory()
    {
        ArrayList directoryListing = new ArrayList();
        StringBuilder storedPath = new StringBuilder();            

        foreach (var directories in storedPreviousDirectory.Split('/'))
        {
            storedPath.Append(directories + "/");                
        }

        storedPath.Replace("//", "/");
        directoryListing = iPhoneFileSystemBrowse(storedPreviousDirectory);

        return directoryListing;
    }

1 个答案:

答案 0 :(得分:1)

试试这个:

string input = "/var/mobile/Documents/";
var parts = input.Split(new []{'/'}, StringSplitOptions.RemoveEmptyEntries).ToList();
parts.RemoveAt(parts.Count - 1);
string output = string.Concat("/", string.Join("/", parts), "/");