c# 枚举安卓系统中所有目录及文件名

Posted 空明流光

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c# 枚举安卓系统中所有目录及文件名相关的知识,希望对你有一定的参考价值。

using android.App;
using Android.Widget;
using Android.OS;
using System.Runtime.InteropServices;

namespace App2
{
    [Activity(Label = "App2", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        [DllImport("TestDynamicSharedLib.so")]
        public extern static int getClickCount();

        protected override void OnCreate(Bundle bundle)
        {
            var c = getClickCount();

            //string folderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System);

            printAllSubFiles("/");

            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            // SetContentView (Resource.Layout.Main);
        }

        void printAllSubFiles(string path)
        {
            System.Diagnostics.Debug.Print("dir:" + path);

            var dir = new System.IO.DirectoryInfo(path);

            try
            {
                foreach (var f in dir.GetFiles())
                {
                    System.Diagnostics.Debug.Print("file:" + f.FullName);
                }
            }
            catch 
            {
                //throw;
            }

            try
            {
                foreach (var d in dir.GetDirectories())
                {
                    printAllSubFiles(d.FullName);
                }
            }
            catch (System.Exception)
            {
                //throw;
            }
            
        }
    }
}

 

以上是关于c# 枚举安卓系统中所有目录及文件名的主要内容,如果未能解决你的问题,请参考以下文章

怎样能看到安卓系统手机的c盘文件及文件夹?

c#遍历目录及子目录下某类型的所有的文件

C# 获得目录创建时间的源码片段

Unity C# 读取安卓persistentDataPath目录中的json文件

在c#中获取所有枚举值的简单方法

Windows 驱动内核:如何枚举所有子目录和文件?