Main Site Documentation

Directory.Move(sourceDirectory, destinationDirectory);


#1

Using: Libs version 1.0.0-preview2 and 1.0.0-preview3 - Neither worked for Move

I have been trying to use Directory.Move(sourceDirectory, destinationDirectory);

I never receive exceptions in Try Catch.

Maybe I am the problem but I thought I would let you know anyway.

            //StorageController sc
            if (sc == null) 
            {
                sc = StorageController.FromName(@"GHIElectronics.TinyCLR.NativeApis.STM32F7.SdCardStorageController\0");
                drive = FileSystem.Mount(sc.Hdc);
            }
            //

            //These directories already exist on the SD Card. Each has a small text file in the folder
            //drive.CreateDirectory($@"{drive.Name}FolderToMove");
            //FolderToMove.txt
            //drive.CreateDirectory($@"{drive.Name}FolderToMoveTo");
            //FolderToMoveTo.txt

            DirectoryInfo di0 = new DirectoryInfo($@"{drive.Name}FolderToMove");
            DirectoryInfo di1 = new DirectoryInfo($@"{drive.Name}FolderToMoveTo");

            if (di0.Exists && di1.Exists)
            {
                string sourceDirectory = $@"{drive.Name}FolderToMove";
                string destinationDirectory = $@"{drive.Name}FolderToMoveTo";

                try
                {
                    // Tried both ways - No exceptions received using either one
                    //Directory.Move(sourceDirectory, destinationDirectory);
                    Directory.Move(di0.Name, di1.Name);
                }
                catch
                {
                    // No exceptions received
                    screen.DrawString("Directory.Move ERROR", droidreg12, BrushRed, 450, 210);
                    screen.Flush();
                }
                //
            }
            //  
            else
            {
                screen.DrawString(di0.Name + " & " + di1.Name + " do not exist.", droidreg12, BrushRed, 405, 182);
                screen.Flush();
            }
            //

#2

We’ll take a look and let you know what we find


#3

Thanks. Not really a problem. I just thought I would let you know.

I was not sure if it was an error in my test code.


#4

Thanks for pointing things out. Please do not feel like you can’t share anything you find with us. We are here to help and make TinyCLR the best it can be :slight_smile:


#5

Did you remember call FileSystem.Flush before take SD out?

Also, destination folder must be not exist. Following your example, I think you want d0.name is inside di1.Name, it should be:

‘Directory.Move(di0.Name, di1.Name\d0.name);’


#6

Thank you for the reply.

I had the destination folder on the card before using move.