Unity:如何从给定路径获取文件名?

问题描述 投票:0回答:1

我想从给定路径获取文件名。例如,我有一个类似/storage/emulated/0/AlbumFolder/Images/20190512_14859.jpg的路径,那么我怎么只提取20190512_14859.jpg

我在UIText中具有路径:public Text ImagePath; imageFilePath = ImagePath.text;之所以这样设置,是因为该路径是从另一个脚本中获取的,该脚本使用一个称为UnityNativeGallery的统一插件。因此,在另一个脚本中,它调用了进入文本的路径,然后从上面的当前脚本中获得了该文本。

现在我只想要文件名。我发现:

    / taking full path of a file 
    string strPath = "C:// myfiles//ref//file1.txt"; 

    // initialize the value of filename 
    string filename = null; 

    // using the method 
    filename = Path.GetFileName(strPath); 

但它似乎不适用于我的代码。然后我想将文件名写入创建的txt文件中,如:

    string albumDetails = albumName + "|" + albumDate + "|" + albumDescription;
    string NewTextfile = newFolder + "/" + albumName + ".txt";
    File.WriteAllText(NewTextfile, albumDetails);
c# file unity3d filenames filepath
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.