Enumerate Directories

PDF for offline use
Sample Code:

Let us know how you feel about this

Translation Quality


0/250

This recipe shows how to list directories in the iOS file system using Xamarin.iOS.

Recipe

You can list the directories in a Xamarin.iOS application in the following ways:

  • To list the directories in the application bundle, call EnumerateDirectories with the current path syntax:
var directories = System.IO.Directory.EnumerateDirectories("./");
  • To list the directories in the application’s home directory, construct the path like this:
var path = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
directories = System.IO.Directory.EnumerateDirectories(path+"/..");
  • The directory list is returned as IEnumerable<string> which can be output to the Console or a UITextView:
foreach (var directory in directories) {
    Console.WriteLine(directory);
    txtView.Text += directory + Environment.NewLine;
}

The sample application output displays all the output from step 1 and step 2:

Additional Information

Remember that the iOS file system is case-sensitive (although the simulator is not). Ensure that you type file and directory names correctly.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.