Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Android get file paths?

Discussion in 'Scripting' started by nbfp, Oct 25, 2018.

  1. nbfp

    nbfp

    Joined:
    Jul 30, 2015
    Posts:
    23
    HI,

    Can someone help me how to get file paths from Android device (Oculus Go in my case). The following code does find all files, but the line
    lista.Add(f.ToString());
    only adds the filename to list when deployed to Oculus Go. In editor it works just fine and shows the full path to the file in question.

    Code (csharp):
    1.  
    2. private List<string> lista = new List<string>();
    3. private List<string> nimilista = new List<string>();
    4.  
    5.  
    6. dir = new DirectoryInfo("/mnt/sdcard/Videos/");
    7.  
    8. FileInfo[] info = dir.GetFiles("*.*", SearchOption.AllDirectories);
    9.  
    10.         foreach (FileInfo f in info)
    11.         {
    12.             if(Path.GetExtension(f.ToString()) == ".mp4")
    13.             {
    14.                 //This is a list that I am having problems with
    15.                 lista.Add(f.ToString());
    16.  
    17.                 //This is a list
    18.                 nimilista.Add(Path.GetFileName(f.ToString()));
    19.              
    20.             }
    21.         }
    22.  
     
    Last edited: Oct 25, 2018
  2. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    nbfp likes this.
  3. nbfp

    nbfp

    Joined:
    Jul 30, 2015
    Posts:
    23
    Thank you nilsdr.
    f.FullName worked like a charm. I have no idea why simply f.ToString didn't work.
    Spent the whole of yesterday trying to figure this out by my self. Sometimes it might be a time saver to ask someone who actually knows what they are doing:).
     
    nilsdr likes this.