Copy one file in every folder

Hello i want to create robot which will copy one file and will paste it in each folder. Let’s say i have in one folder 100 folders and i want this file to be copied in each folder. Thanks in advance for suggestions.

Best regards.

Hi,

you can try the following steps.

  1. Build a collection that contains directory of all the 100 folders

( string[] allfiles = Directory.GetFiles("path/to/dir", "*.*", SearchOption.AllDirectories);) or if you want the directories only then Directory.GetDirectories("YourMainFolderAbsolutePath")

  1. Loop through each directory item (each folder int he string array)
  2. use copy file activity in the loop

Hope this helps

PS : You need to convert the C# syntax to VB though.

2 Likes

Hello when i try to assign this ( string[] allfiles = Directory.GetFiles("path/to/dir", "*.*", SearchOption.AllDirectories); ) i got error message which shows : Compiler error(s) encountered processing expression

Well,

For your reference here is a screenshot for the same.

Hello

For destination what i need to put.

From : Your file path (absolute)

To : “Folder.ToString” (Folder is your variable item where all the collection items will be referenced in the loop)

Main.xaml (5.3 KB)

I got error on this one.

image

But the excel file is not used by anything else and it’s not open.

it was because the file was in the same folder where i got all other folders , but even if i move the file robot execute the process and there is nothing in the folders they are all empty it’s not pasting the file.

@Raghavendraprasad

If that file is being used by a process you might have to close excel app before copying (or kill process) might be a background process running is still accessing it.

No it’s not used in background , i test it out now when i moved the file to another place and when i create in each folder new excel file with the name template after that the executing is working I,m not sure why this copy file works only on files and not in directories it’s not copying the file and placing it in the directory it requires to have the same file name than will overwrite it which is so strange.

image

if i include a excel file with the name template it overwrites it and it’s working.

Hello ,

Thank you for the help i manage to do this with script.bat file which copy the file and paste it in each folder i guess works better than the robot for now. I will look on to the other issue with the output and input folders.

Hi, Pardon the delay in response.

Seems like an easy process no script needed. I have attached a sample xaml (very skeletal workflow do check it out)

Sequence.xaml (6.0 KB)

Do get back if this is what you intended

I just test it out and when i run the robot the folders inside don’t have anything they are empty the file is not copied.

Can you share your workflow on how you modified it?

Hello

I have basically did that you mention in comments in From i put the location on the file which i want to copy.

And in assign in path to dir i place the path to the main folder which contain all other sub folders where file need to be copied.

You are doing directory.getFiles and it will get only PDF files but we are supposed to be looping through folders in a 'main’folder so looping for the files will not work.

You need to tweak the code to :slight_smile:

  1. Get all sub folders in a ‘main’ folder
  2. THen loop through the subfolders in which the file needs to be copied.

But here we are not looping pdf files it’s i just need to copy one file in for example 100 sub folders.

Then in the Directory.Getfiles function remove the *pdf because you will get only the PDF files in a main folder.

The top directories are your target folders to copy each file hence the loop should act for the sub folders not the files. The code needs to be tweaked

There is no pdf in the getfiles directory it’s : Directory.GetFiles(“path to main folder”, “.”, SearchOption.AllDirectories)

Okay,

There is a main folder and you want to read pdf files if they are present in all subfolders and keep the resulting text file in the same sub-folder am I correct in understanding the requirement?