Search Unity

Simple File Browser [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Nov 19, 2016.

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Good question. I don't know if my plugin supports browsing files on a network, I haven't tried it. Does the path
    \\design\classroom\examples
    work when you type it into the path field manually?
     
  2. gigolv

    gigolv

    Joined:
    Sep 30, 2017
    Posts:
    6
    nop... it only works when the files are stored in either the same PC (windows build) or the Android device... I haven't been able to find out what the path should be for a shared folder.

    I managed to add the shared folder to an app called ES File Explorer and I can browse the files there, but unfortunately the other computer isn't showing in your browser app... it only lists the local devices or the external SD card on my Android, but it doesn't show any Network shares to connect to nor can I enter the path manually to it.

    Thanks for any Ideas... I have been trying to get the path to work on Android for over a week now and Im a bit bedazzeled by the matter.

    is there any way we could view network shares or perhaps map a drive in android a similar way it is done in windows?

    thanks again and excellent work with the app its very useful.
     
  3. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    If Directory.GetFiles supports network shares, then it should be possible to list files in a network share. If manually entering the path of the network folder doesn't work, then it doesn't seem to be possible. In this case, I'm not sure how to access the network folder.
     
  4. gigolv

    gigolv

    Joined:
    Sep 30, 2017
    Posts:
    6
    thanks... ill keep investigating then... thanks again for your feedback.
     
    yasirkula likes this.
  5. Shanmf3d

    Shanmf3d

    Joined:
    Aug 1, 2017
    Posts:
    8
    You should be able to use the quicklink to do it. You'll need to specify the drive, and don't have the image name in the link.
    so : "\\design\classroom\examples\design.jpg"
    should be: "drive:\\design\classroom\examples\"
    => FileBrowser.AddQuickLink("Examples", "Y:\\design\classroom\examples", null);
     
    yasirkula likes this.
  6. DDAUDIOSOLUTIONS

    DDAUDIOSOLUTIONS

    Joined:
    Sep 5, 2015
    Posts:
    21
    Hi, Thanks a lot, for this package, is very useful. I have a doubt. I have the filebrowser.result, that i can print in console, but i would like to use this like a text in a inputfield in canvas, to reproduce a music, that i select with your asset. How can i convert filebrowser.result to string? thanks
     
  7. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    It is already a string. You can simply use
    textObject.text = FileBrowser.Result;
     
  8. gigolv

    gigolv

    Joined:
    Sep 30, 2017
    Posts:
    6
    Thanks for the feedback, excellent idea!. The only problem is that im trying to access the shared folder from an Android device and the shared folder hasn't been mapped to any drive yet... im not sure how to map it to a drive in an android device... should I use es File Explorer for that beforehand? is the Y: drive supposed to have the shared folder mapped onto it outside the app?

    I tried do add the quickLink refference in the file browser, but it doesn't seem to be working unfortunately.
     
  9. v_osnovnom_bezvreden

    v_osnovnom_bezvreden

    Joined:
    Jan 9, 2017
    Posts:
    7
    Does this asset support macOS?
    Thank you!
     
  10. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    It should, yes.
     
  11. BasPasut

    BasPasut

    Joined:
    Feb 4, 2019
    Posts:
    1
    I want a path as string to the selected file, but OnSuccess always false when I selected the file. How can I fix this problem? Please help me.
     
  12. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Can I see your code?
     
  13. jeffdyerSRTMarine

    jeffdyerSRTMarine

    Joined:
    Jan 23, 2019
    Posts:
    12
    We have a multi display application, how can I make the file browser appear on a specific display?
     
  14. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    File browser is basically a regular UI canvas. You can make FileBrowser.Instance public and then use that variable to access the canvas of the file browser and anchor it to the second display (I don't know how it is achieved, I have a single monitor XD).
     
  15. jeffdyerSRTMarine

    jeffdyerSRTMarine

    Joined:
    Jan 23, 2019
    Posts:
    12
    I added this to my FileBrowser.cs

    Code (CSharp):
    1.         public static FileBrowser GetInstance()
    2.         {
    3.             return m_instance;
    4.         }
    5.  
    and then this code to get the targetDisplay and centre the FileBrowser - seems to work for me.

    Code (CSharp):
    1.            
    2. FileBrowser.ShowLoadDialog(OnLoadTRRSuccess, OnLoadTRRCancel, false, Path.Combine(Application.streamingAssetsPath.Replace(" / ", "\\"), "Recordings"),
    3.                 "Load TRR file", "Load");
    4.  
    5.             Canvas fbCanvas = FileBrowser.GetInstance().gameObject.GetComponent<Canvas>();
    6.             if (fbCanvas != null)
    7.             {
    8.                 fbCanvas.targetDisplay = viewerMain.MainCamera.targetDisplay;
    9.                 RectTransform rectTransform = fbCanvas.GetComponent<RectTransform>();
    10.  
    11.                 rectTransform.anchoredPosition = new Vector2(Display.displays[viewerMain.MainCamera.targetDisplay].renderingWidth / 2, Display.displays[viewerMain.MainCamera.targetDisplay].renderingHeight / 2);
    12.             }
    13.  
    Thanks.
     
    yasirkula likes this.
  16. atreyu64

    atreyu64

    Joined:
    Feb 12, 2017
    Posts:
    6
    Hi, I have a problem on Android, with SimpleFileBrowser.jar which does not seem to be found.
    It used to work great on Unity 2018, but since I had to upgrade to Unity 2019 this problem appeared.
    I tried to update SimpleFileBrowser to the last version, but it didn't help.
    Any idea of what could cause this ?

    Thanks in advance, cheers from France !


     
  17. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Adding the following line to ProGuard filters should resolve the issue:
    -keep class com.yasirkula.unity.* { *; }
     
  18. atreyu64

    atreyu64

    Joined:
    Feb 12, 2017
    Posts:
    6
    It worked, thank you so much !
    Your plugin is extremely usefull, congratulations and thanks again !
     
    yasirkula likes this.
  19. yinono

    yinono

    Joined:
    Sep 15, 2010
    Posts:
    27
    Hi,
    Great plugin, it realy works well for us.
    We want to add Keyboard support, so it'll be possible to navigate using arrow keys.
    Can you point me to the best place in the code to implement such support?

    Thanks
     
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Changing the base class of ListItem to UnityEngine.UI.Selectable makes keyboard navigation somewhat possible. Then, implementing the UnityEngine.EventSystems.ISubmitHandler interface as following makes the submit (Enter) button work:

    Code (CSharp):
    1. public void OnSubmit( UnityEngine.EventSystems.BaseEventData ev )
    2. {
    3.     UnityEngine.EventSystems.IPointerClickHandler clickHandler = GetComponent<UnityEngine.EventSystems.IPointerClickHandler>();
    4.     if( clickHandler != null )
    5.         clickHandler.OnPointerClick( null );
    6. }
    However, as the file browser uses a recycled list view, 5 items (GameObjects) may be used to show 500 files in a directory. You'd have to scroll the Files scroll view manually by code when the highlighted file is almost at the upper or lower bound of the scroll view.
     
  21. danielos1996

    danielos1996

    Joined:
    Sep 6, 2018
    Posts:
    3
    Do you plan on adding support for UWP? would love to get something like this working in the Windows VR headset.
     
  22. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  23. stklsrvs

    stklsrvs

    Joined:
    Jun 24, 2019
    Posts:
    3
    Sorry, I do not have much experience in programming. I'm trying to create a dialog box after the user clicks a button. This is the DownloadFile () method:

    SimpleFileBrowser.FileBrowser.ShowLoadDialog((path) => { Debug.Log(path); }, null,
    false, null, "Select File", "Select ");

    I do not understand how I can change the default path directory (Documents to C:\\) and How can l set the default filter ".xml".

    This code does not work:

    SimpleFileBrowser.FileBrowser.ShowLoadDialog((path) => { Debug.Log(path); }, null,
    false, null, "Select File", "Select ");
    FileBrowser.SetDefaultFilter(".xml");
    FileBrowser.AddQuickLink("Users", "C:\\Users", null);
     
  24. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Try this:

    Code (CSharp):
    1. string pathC = Path.GetPathRoot( Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments ) );
    2. FileBrowser.SetFilters( false, ".xml" );
    3. FileBrowser.SetDefaultFilter( ".xml" );
    4. FileBrowser.ShowLoadDialog( ( path ) => { Debug.Log( path ); }, null, false, pathC, "Select File", "Select " );
     
    stklsrvs likes this.
  25. stklsrvs

    stklsrvs

    Joined:
    Jun 24, 2019
    Posts:
    3
    Many thanks!
     
  26. stklsrvs

    stklsrvs

    Joined:
    Jun 24, 2019
    Posts:
    3
    I have one more question: Is it possible to display the standard Windows folders in the dialog box on user's native language? For example, "the documents or desktop" folder on the attached to my post screen:


    And is it possible to translate into the native language other interface elements of the dialog box?
     

    Attached Files:

  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Localization is definitely one of the weakest points of this asset. You'll have to translate those texts manually. This is easy for static texts like "Show hidden files" or "Search..." but for the others, you'll have to modify FileBrowser.cs.

    The documents and desktop quick links are defined inside the SimpleFileBrowserCanvas prefab's "Quick Links" property. To localize them, you'd need to remove them from "Quick Links" and call
    FileBrowser.AddQuickLink
    from your own script to add them to the file browser with a localized string.
     
    stklsrvs likes this.
  28. mama24012004

    mama24012004

    Joined:
    Apr 1, 2019
    Posts:
    1
    Hello, how can I select an image for my object? Please I need help
     
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  30. mrelytra

    mrelytra

    Joined:
    Jan 16, 2019
    Posts:
    2
    Hello!
    I'm trying to make a PNG exporter, but i can't find a way on how to access the filename bar string to name the file that user wanted to export.

    Thanks
     
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Inside the OnSuccess callback, you can call
    System.IO.Path.GetFileName(path)
    . If you are using the coroutine approach, you can call
    System.IO.Path.GetFileName(FileBrowser.Result)
    .
     
  32. AlaaMEbr

    AlaaMEbr

    Joined:
    Jun 11, 2019
    Posts:
    4
    Hey
    really great work
    I am a beginner so question could be silly
    i wanna use this plugin for browsing text file in an android application
    and text file will be in my internal or external i don't care for the location on phone
    how can i do it?
    i use the code you put on GitHub but i can't complete on it
     
  33. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    How about this:

    Code (CSharp):
    1. SimpleFileBrowser.FileBrowser.SetFilters( false, ".txt" );
    2. SimpleFileBrowser.FileBrowser.ShowLoadDialog( (path) =>
    3.     {
    4.         Debug.Log( "Selected file path: " + path );
    5.     }, () =>
    6.     {
    7.         Debug.Log( "Canceled" );
    8.     }, false, null, "Select a text file", "Select" );
     
    AlaaMEbr likes this.
  34. AlaaMEbr

    AlaaMEbr

    Joined:
    Jun 11, 2019
    Posts:
    4
    Yeah Thnx
    you are a life saver:)
     
  35. BayuSM

    BayuSM

    Joined:
    Dec 16, 2018
    Posts:
    5
    I already download this asset and it very good.but i dont know how to get name from result load.please help me
     
  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    The OnSuccess callback (first parameter of the ShowSaveDialog and ShowLoadDialog functions) takes a string parameter. It holds the absolute path of the selected file/folder. If you want to get the filename from it, you can use the System.IO.Path.GetFileName(path) function. The example code might help you understand the callback better: https://github.com/yasirkula/UnitySimpleFileBrowser/#example-code
     
  37. BayuSM

    BayuSM

    Joined:
    Dec 16, 2018
    Posts:
    5
    Thanks.it worked
     
    yasirkula likes this.
  38. said123sawn

    said123sawn

    Joined:
    Oct 31, 2019
    Posts:
    26
    hello, I want a selected song to be transferred to the audio source component

    can you give an example, please:(
     
  39. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Please check out this link. I basically googled "unity load audio clip from file"
     
  40. said123sawn

    said123sawn

    Joined:
    Oct 31, 2019
    Posts:
    26
    for this Windows I want for android
     
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Please don't get me wrong but this is outside the scope of SimpleFileBrowser; it is just responsible from selecting a file and returning its path. It is then up to you to process that file. I don't know how to load an audio file at runtime either, so you should search the topic yourself.
     
  42. said123sawn

    said123sawn

    Joined:
    Oct 31, 2019
    Posts:
    26
    Ok thanks
     
  43. Cloudlet

    Cloudlet

    Joined:
    Jan 6, 2019
    Posts:
    4
    Great stuff! Thank you so much! One question: is it possible, after selecting a file, to get the path without it? I want it to remember the last folder that was used and make it the default one. Not sure how to get the path to folder without the filename.
     
  44. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can get the directory of a path via
    System.IO.Path.GetDirectoryName(path)
    . File browser remembers the last location and continues from there if you don't provide an initialPath parameter while showing the dialog. However, the path doesn't persist between app sessions, so when you close the app, the last path will not be remembered. You can use PlayerPrefs to save/load the last path yourself and pass it to the ShowSaveDialog/ShowLoadDialog functions, if you want.
     
  45. Cloudlet

    Cloudlet

    Joined:
    Jan 6, 2019
    Posts:
    4
    Oh, yeah, didn't notice that it saves by default. Thanks! Another question then: can I make it focus on a file that was loaded last? I have lots of files in a folder, images, I'm loading them one at a time, what I want is for the browser, when I open it, to scroll down to the last file opened so that I don't have to. Is it possible?
     
  46. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Well, surely it can be achieved with some modifications to FileBrowser.cs. You'd have to store the name of the previously selected file in a variable and focus on that file in RefreshFiles.
     
  47. akuja

    akuja

    Joined:
    Jul 11, 2018
    Posts:
    2
    Hi, great job with the file browser! I'm just having one problem, I can't type into any of the input fields in the browser window, any idea what I'm doing wrong? I'm using Unity 2018.1.5f1, and this is how I open the browser:

    FileBrowser.SetFilters(false, new FileBrowser.Filter("OBJ files", ".obj"));
    FileBrowser.ShowSaveDialog((path) => {
    StartCoroutine(DownloadOSMFile(OSMqueryURL, osmfilename, path));
    },
    () => { Debug.Log("Canceled"); },
    false, null, "Save obj file", "Select");
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Please make sure that there is an active EventSystem object in the scene. If there is one, try deactivating and then reactivating it. Also, are there any error messages?
     
  49. akuja

    akuja

    Joined:
    Jul 11, 2018
    Posts:
    2
    Reactivating EventSystem had no effect, and there are no error messages either. I just tried adding a new Input Field on the canvas and that doesn't let me type into it either, so the problem is definitely on my side. I need to figure this out myself, sorry for the trouble and thanks for trying to help.

    Edit: The issue was that I had a
    EventSystem.current.SetSelectedGameObject(null);
    in one of my Update functions.
     
    Last edited: Nov 8, 2019
    yasirkula likes this.
  50. thao050192

    thao050192

    Joined:
    Jul 17, 2017
    Posts:
    5
    How can i filter all file with extenxion file in all disc like .png in my disc native ? Thank Bro
     
    Last edited: Nov 14, 2019