Is there a way to move all files at one go from folder to folder

Hi,

Is there as way I can move all files(I have 1000 .pdf files to move each time) from folder to folder in one go? I know how to do that using the for each loop, but that’s taking a very long time(30 minutes to move 600 files) to move all files. I will have around 1000 files to move each time. So, trying to find a better solution to improve performance.

@Krithi1 - we can try with Array.foreach code. I guess I have a sample somewhere, let me find it and share.

@Krithi1 - Here you go…

image

Sample Code: Here I am moving the files from DeleteFiles folder to MoveFiles Folder…

array.ForEach(Directory.GetFiles("DeleteFiles\", “*”).ToArray,Sub(x) File.Move(x,"MoveFiles\"+ Path.GetFileName(x)))

If you would like to pass the path via variables, please add it to the Edit Arguments.

Note: I don’t think(I may be wrong) there is any other solution than this. Like Pick and drop. But this will improve your performance.

Hope this helps…

@prasath17 - Thank you for sending that code. But I don’t see any performance difference. My files are being moved from a shared rive folder to shared drive folder. Not sure if that takes more time. Local folder to folder is working great with this code, it’s taking from coupe of seconds to few seconds to move in local. Thank you very much

Lets see if anybody else has more solutions.

1 Like

Hi @Krithi1,

Do try what @prasath17 suggested first as the thread will be running from UiPath execution.

Another alternative is going back to PowerShell. PowerShell is extremely fast with such operations and can be integrated well in UiPath: How to Integrate PowerShell with UiPath- Step by Step guide - News / Tutorials - UiPath Community Forum

Another advantage of using PowerShell is that you can use the same approach on mapped network drives as well. Unlike using move from UiPath, which can only do this from 2021.09, if I remember correctly.

All you need is two methods

  1. Get an item (.pdf in your case )
    Get-ChildItem (Microsoft.PowerShell.Management) - PowerShell | Microsoft Docs
  2. Move each item (moves files, so all files from source folder are moved not copied to destination)
    Move-Item (Microsoft.PowerShell.Management) - PowerShell | Microsoft Docs

If you want to copy instead of move
3. Copy-Item (Microsoft.PowerShell.Management) - PowerShell | Microsoft Docs

Your PowerShell code should then be as simple as this. Offcourse you can make the inputs as parameters from UiPath (as shown in the tutorial above).

$SourcePath = "C:\Users\USER\Downloads"
$DestinationPath = "C:\Users\USER\Downloads\New"
Get-ChildItem -Path $SourcePath -Recurse -Force -Include "*.pdf" | Move-Item -Force -Destination $DestinationPath 
2 Likes

@jeevith - we have 2020.10. Does that mean the above powershell commands won’t work?

Hi @Krithi1,

It will work as it has no dependencies with UiPath. PowerShell will run its own execution and UiPath will wait for the execution to end.

Fill in your paramters and it should work for you as well.

I tested this out on a network drive: MovePdfToDestination.xaml (6.0 KB)

1 Like

@jeevith

Thank you, both solutions are working the same way for me. It could be my shared drive network in that case. Ty both for the quick response.

@Krithi1

Its due to the files inside the shared folder but not with UiPath activities and all.

Hi @Krithi1,

Then I am assuming the two shared drives are in different subnets and the communication lag leads to slower execution from PowerShell. Nonetheless, you learnt two new ways of solving your problem and now know that PowerShell can be a fallback. UiPath is great, but PowerShell is more flexible when you cant find a better way in UiPath studio :slight_smile:

Also I think running this in batches is better suited to your case. You can try it yourself, when you copy large number of files, windows file movement has a lot of lag. But if you choose less number of files each time, the move / copy is faster.

If you use batches, you can use all three (for-loop in Studio, array.ForEach, or PowerShell) and will see minimal performance lags between all of them and overall job of moving.

To do this, you need to ensure you have a bin. Say each batch takes 50 from the array where filepath is found. The next batch skips first 50 and takes next 50 and moves them. Repeat this until the end of the array length.

Worth trying if this is a high frequency process, say executed every day by the robot.

When you find a suitable solution, do share it here, we are interested in knowing what solves such a problem!

1 Like

Hi @Krithi1,

I think this might be useful .

One folder can be moved using
Directory.Move(“D:\RPA\exception files\Exception”, “D:\RPA\error files”)

Hi @Krithi1,

Ignore my previous post in this thread. The below is wrong.

I talked to a network drive expert and was told that the fastest way to move files in network drive is moving one big file versus multiple small files. This is because the IO in network drives perform well when the incoming packets are in one chunk and will perform slowly if we do mutiple moves for each file.

So I have edited my suggested solution to zip .pdf files,

  • move the zip file to destination folder
  • unzip the file in the destination folder
  • delete the zip file in the end

The PowerShell code will be:

"Param( 
     [Parameter(Mandatory=$true)] [string]$SourcePath,
     [Parameter(Mandatory=$true)] [string]$DestinationPath
    )
Get-ChildItem -Path $SourcePath -Recurse -Force -Include '*.pdf' | Compress-Archive -DestinationPath $DestinationPath\ZippedPDFFiles 
Expand-Archive -Path $DestinationPath\ZippedPDFFiles.zip -DestinationPath $DestinationPath
Remove-Item –path $DestinationPath\ZippedPDFFiles.zip"

Do try this out it and let us know if this took lesser time or not for your case.

MovePdfToDestination.xaml (7.5 KB)

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.