Move Folder to another Folder

Hi ,

I want to move a folder to another location.
Eg: I have folder C:/Level1/Level2.
I need to move this Level2 folder to C:/Level1/Target.
‘Target’ Folder already exist with other files/folders.
so once done I should find ‘Level2’ in C:/Level1/Target/Level2

Please Note - Its move not copy.

Please provide your suggestions

Hey @Deeipauk,

Maybe these links can help you :slight_smile:

1 Like

Thanks for your reply Rishabh.

In both the cases its given the destination folder should not exist already but in my case the destination already exist with other files/folders. In that destination I need to move some more folders

1 Like

Hi @Deeipauk,

Try using

Directory.Move(sourceDirName, destDirName)

In that case you will need to loop through the files in the folder and copy those to the new folder.

where to write this code? in assignment statement? if you dont mind please provide me some sample .xaml

Thanks for your reply. This will complicate the process.I need to first create a new directory with the same name and move files one by one also internally it may contain sub folders also. So i feel this will complicate?

Correct me if I am wrong

As @sarathi125 suggested, Directory.Move method moves a directory and all its contents, including nested subdirectories and their files, to a new location and if the destination directory already exists, an error occurs.
You cannot use assign activity because return type of this method is none.
You can write this code in invoke method activity with the following options:

  1. Target Type as System.IO.Directory
  2. Method Name as Move
  3. Two parameters in property panel with In and String Type for SourceDirectory and DestinationDirectory.

DirectoryMove

Thanks for your reply

“Invoke Code” – is this the activity I need to use?
When i look at screen shot shot this looks like “Invoke Method” which will throw error since the destination diretiry already exist.

If you don’t mind please provide a sample .xaml

Hello @sarathi125.
How can this be done?
Thank you so much,
Camilla

hi Bharat,

i get an error as Source & destination path must have identical roots. Move will not work across volumes.

Could you please share some details about exactly what u r trying to do and the error u r facing,

i get an error as Source & destination path must have identical roots. Move will not work across volumes.

Am trying to move files in a folder located in share drive to local drive . It is copying the entire folder. unable to do it using move

Please check the XAML attached.
In Simple, we can’t move the folder. So I copied the source folder to destination and deleted the source. It works fine. Please check and confirmsample.xaml (5.1 KB)

MoveDirectory.xaml (10.7 KB)

This will copy a directory and all its subsequent subdirectories and files to your chosen location. Just invoke this somewhere to copy the files and then delete the original folder. Or if you want to, you can replace the ‘Copy file’ activity with a ‘Move’ activity.