Create folders and sub folder if doesn't exists while copying a file

Hi All,

While copying a file from one path to another path, if any of the folders/sub folders doesn’t exists while copying, is there a way to auto create them while copying?

For Eg: If I am trying to copy this file from C:\Users\RPA\Reports\test1234.txt


D:\Users\RPA\OutputFiles\Reports\text1234.txt where “OutputFiles” and “Reports” folders doesn’t not exists. Is there an easy way to create these missing folders automatically, if they do not exists?

@Krithi1 - If I am not wrong…I don’t think Copy File will create a missing folders…

You have to check upfront using System.IO.Directory.Exists(Path) or “Path Exists” (and choose Folder) activity for each subfolders, if it returns false then create a folder and then proceed to copying…


I could think of same thing, but I wanted to check if there an easy and automatic way of doing it, since there are a number of files I need to copy this way. It would be a tedious process to create all those folders if I have to create them using create folder activity.

In addition to what @prasath17 said, there is another way you can explore the powershell feature
I think there is cmdlet which can help you in this case for this
Check it please

Nived N

@Krithi1 - I think I figured it out…In the below code, Guru and Test folder does not exist and when I ran the code, it created and copied the folder…


 My.Computer.FileSystem.CopyFile("C:\Users\giris\Documents\UiPath\Studio\String_Manipulation\DeleteFiles\201872 Invoice Penalty Charge.pdf.txt", "C:\Users\giris\Documents\UiPath\Studio\String_Manipulation\DeleteFiles\Guru\Test\201872 Invoice Penalty Charge.pdf.txt")


Hope this helps…


@prasath17 - yes that worked. Thank you for the quick help

@NIVED_NAMBIAR - thanks for letting me know about that feature

1 Like

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