Hi Rudy,
My Dev-VM won't let me run an F&O project so I can't test your code. But looking at it I assume it will work.
The Sytem.IO docs tell me an IOException will be thrown with Directory.Move() and File.Move() if the destination or file already exists. From your code if, C:\Test_Destination exists, you should get an Error::IOException
I confirm that speculation with a console app on my VM. The below code works to your requirements if Bob2 does not exist. it works the first time, then after putting the Bob folder back it will fail with an IOException error the second time because Bob2 folder exists
class Program
{
static void Main(string[] args)
{
string source = "C:\\Bob";
string destination = "C:\\Bob2";
System.IO.Directory.Move(source, destination);
}
}
------------------------------
Bob Coward
Dynamics AX/F&O Developer
DSG
Grayson GA
------------------------------
Original Message:
Sent: Feb 24, 2021 10:57 AM
From: Rudy Salcedo
Subject: Moving subfolders to a different folder via X++
@Bob Coward, thanks for the suggestion. I did see that blog earlier and tried to tweak it for our purposes, but couldn't get it to work. I haven't used Directory::Move before, so do you see anything wrong with the code that's preventing the folder from being moved?

------------------------------
Rudy Salcedo
Senior Programmer/Analyst
LaForce, Inc
Green Bay WI
Original Message:
Sent: Feb 23, 2021 05:25 PM
From: Bob Coward
Subject: Moving subfolders to a different folder via X++
Hi Rudy,
I do not have access to a 2012 VM but please verify this can't be done using namespace System.IO.Directory::Move(Source, Destination) type solution.
Refer here: https://aristonjavier.wordpress.com/2015/10/21/ax-2012-moving-file-to-another-folder-using-system-io-file/
See if you can't change System.IO.File::Move to System.IO.Directory::Move and get the results you expect.
Bob Coward
------------------------------
Bob Coward
Dynamics AX/F&O Developer
DSG
Grayson GA
Original Message:
Sent: Feb 23, 2021 04:19 PM
From: Rudy Salcedo
Subject: Moving subfolders to a different folder via X++
Is there a way in AX 2012 to move a subfolder and all of its contents to a different folder via X++? All the examples I've seen so far only show how to move a file from one folder to another folder. For our purposes I need to move a subfolder and everything in it to a different folder.
For example I need to move both test subfolders and their contents from C:\TEST_SOURCE to C:\TEST_DESTINATION, leaving C:\TEST_SOURCE empty when finished.

Can this be accomplished via X++ code? I know it can be done in .NET, but for our application we want to do it in X++ as part of a batch job that runs other processes in AX to determine which folders should be moved. So we need to be able to move the folders one at a time since not all folders will be moved.
------------------------------
Rudy Salcedo
Senior Programmer/Analyst
LaForce, Inc
Green Bay WI
------------------------------