2 回答

TA貢獻1890條經驗 獲得超9個贊
不要使用字符串連接+
和/
獲取系統路徑。
而是始終使用Path.Combine
它根據目標平臺自動使用正確的路徑分隔符。
另外,您使用path.Split('\\');
此功能的地方可能適用于路徑分隔符所在的 Windows,\
但可能不適用于通常使用路徑分隔符的 Android,/
因此最好split
使用Path.DirectorySeparatorChar
在循環中執行它是相當多余的,即使您出于Split
某種原因想要使用它,只需執行以下操作就會更有效
var?temp?=?path.Split(Path.DirectorySeparatorChar); var?filename?=?temp[temp.Count?-?1];
或者直接使用Path.GetFileName
它僅返回給定路徑的文件名部分。
FileBrowser.ShowLoadDialog(
? ? (path) =>?
? ? {
? ? ? ? var temp = Path.GetFileName(path);
? ? ? ? var dir = Path.Combine(Application.persistentDataPath, "upload");
? ? ? ? if (!Directory.Exists(dir))?
? ? ? ? {
? ? ? ? ? ? Directory.CreateDirectory(dir); // create /Upload dir
? ? ? ? ? ? // WHY DO YOU RETURN HERE?
? ? ? ? ? ?//return;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? Debug.Log("That path exists already.");
? ? ? ? }
? ? ? ? try
? ? ? ? {?
? ? ? ? ? ? //Move the selected file
? ? ? ? ? ? var filePath = Path.Combine(dir, filename);
? ? ? ? ? ? File.Move(path, filePath);?
? ? ? ? ? ? Debug.Log(filePath);
? ? ? ? ? ? text.GetComponent<Text>().text = filePath;
? ? ? ? }
? ? ? ? catch(Exception e)
? ? ? ? {
? ? ? ? ? ? text.GetComponent<Text>().text = e.ToString();
? ? ? ? }
? ? ?},?
? ? ?() => { Debug.Log( "Canceled" ); },?
? ? ?false,?
? ? ?null,?
? ? ?"Select Folder",?
? ? ?"Select"
);

TA貢獻1865條經驗 獲得超7個贊
有時,當將項目保存在路徑名很長的驅動器中時,會發生此錯誤,我不記得了,但路徑名有字符限制,我已將項目保存在文件夾內的文件夾中,當我從文件夾中剪切項目時從子文件夾粘貼到主文件夾中,然后路徑大小減小,然后再次統一添加項目并打開,然后就沒有錯誤了。
- 2 回答
- 0 關注
- 711 瀏覽
添加回答
舉報