コード例 #1
0
ファイル: Program.cs プロジェクト: valoni/FatFsFez
        static void MountDrive()
        {
            res = Ff.Current.f_mount(ref fs, "", 1);     /* Give a work area to the default drive */
            res.ThrowIfError();

            Debug.WriteLine("Drive successfully mounted");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: valoni/FatFsFez
        static void DeleteFileExample()
        {
            res = Ff.Current.f_unlink("/sub1/File2.txt");     /* Give a work area to the default drive */
            res.ThrowIfError();

            Debug.WriteLine("File successfully deleted");
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: valoni/FatFsFez
        static void RenameFileExample()
        {
            /* Rename an object in the default drive */
            res = Ff.Current.f_rename("/sub1/File1.txt", "/sub1/File2.txt");
            res.ThrowIfError();

            Debug.WriteLine("File successfully renamed");
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: valoni/FatFsFez
        static void ListDirectoryExample()
        {
            res = Ff.Current.f_mount(ref fs, "", 1);
            res.ThrowIfError();

            res = Scan_Files("/");
            res.ThrowIfError();

            Debug.WriteLine("Directories successfully listed");
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: valoni/FatFsFez
        static void ReadFileExample()
        {
            if (Ff.Current.f_open(ref Fil, "/sub1/File1.txt", FA_READ) == Ff.FRESULT.FR_OK)
            {                                                                   /* Create a file */
                var newPayload = new byte[5000];
                res = Ff.Current.f_read(ref Fil, ref newPayload, 5000, ref bw); /* Read data from file */
                res.ThrowIfError();

                var msg = Encoding.UTF8.GetString(newPayload, 0, (int)bw);
                Debug.WriteLine($"{msg}");

                res = Ff.Current.f_close(ref Fil);                              /* Close the file */
                res.ThrowIfError();
            }

            Debug.WriteLine("File successfully read");
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: valoni/FatFsFez
        static void CreateFileExample()
        {
            if ((res = Ff.Current.f_open(ref Fil, "/sub1/File1.txt", FA_WRITE | FA_CREATE_ALWAYS)) == Ff.FRESULT.FR_OK)
            {   /* Create a file */
                Random rnd     = new Random();
                var    payload = $"File contents is: It works ({rnd.Next()})!".ToByteArray();
                res = Ff.Current.f_write(ref Fil, payload, (uint)payload.Length, ref bw);    /* Write data to the file */
                res.ThrowIfError();

                res = Ff.Current.f_close(ref Fil);   /* Close the file */
                res.ThrowIfError();
            }
            else
            {
                res.ThrowIfError();
            }

            Debug.WriteLine("File successfully created");
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: valoni/FatFsFez
        static void CreateDirectoriesExample()
        {
            res = Ff.Current.f_mkdir("sub1");
            if (res != FRESULT.FR_EXIST)
            {
                res.ThrowIfError();
            }


            res = Ff.Current.f_mkdir("sub1/sub2");
            if (res != FRESULT.FR_EXIST)
            {
                res.ThrowIfError();
            }

            res = Ff.Current.f_mkdir("sub1/sub2/sub3");
            if (res != FRESULT.FR_EXIST)
            {
                res.ThrowIfError();
            }

            Debug.WriteLine("Directories successfully created");
        }