gkngkc / UnityStandaloneFileBrowser

A native file browser for unity standalone platforms
MIT License
2.01k stars 317 forks source link

How to get the file name I write in the File Dialog? #1

Closed tomaszzackiewicz closed 7 years ago

tomaszzackiewicz commented 7 years ago

Hi,

It's not an issue because your code works great, but a question. I need to get the file name I write in the File Dialog to use it in a binary serlialization code. I have your code and the serialization code and now I need to join them into one piece of code. How to do that?

gkngkc commented 7 years ago

Hi,

SaveFilePanel returns selected path, you can use System.IO.Path.GetFileNameWithoutExtension(path) to get entered filename

tomaszzackiewicz commented 7 years ago

How to use Application.persistentDataPath in your FileDialogs?

gkngkc commented 7 years ago

If you want to open PersistentDataPath as initial directory of dialog, you can pass İt to "directory" parameter.

gkngkc commented 7 years ago

Sample code: https://github.com/gkngkc/UnityStandaloneFileBrowser/blob/master/Assets/StandaloneFileBrowser/Sample/StandaloneFileBrowserSample.cs

tomaszzackiewicz commented 7 years ago

Ok, thank you. I understand.

I can get the file name in SaveFileDialog with System.IO.Path.GetFileNameWithoutExtension(path), but it doesn't work with OpenFileDialog. OpenFilePanel returns a string array. How to grab the file name to open it in my serializer code?

gkngkc commented 7 years ago

You right, since OpenFileDialog supports multiple file selection, it returns an array of paths. If user selects one file you can get file path from first index. Like:

var paths = StandaloneFileBrowser.Open(... string path = paths[0];

tomaszzackiewicz commented 7 years ago

Ah, it's the first path in the array! Now, it's clear.

Thank you very much for your help!

All the best!

gkngkc commented 7 years ago

You're welcome.