Error in copying files

Hello there,

I would like to create an automation which will read numbers from a txt file, after that it will read the names of the files in a specific folder and if any of the previously read number are in any name of the files, it should copy the file to an other folder.
I made the below automation, it does not show error but nothing happen when i start it.
Can you please help me what can be the issue? I think something is with the copying method.

Hi @Levente_Csontos_HU

First check by using message box to check if the bot enters into the if condition or not.

Use assign activity to store the array of files and pass that variable in for each.

Before if condition take another assign to store the file name.
name = System.IO.Path.GetFileNameWithoutExtension(filesArray)

if(name.contains(numbersList))
then copy file - Check overwrite

Hi @supriya117

Unfortunatelly I do not have assign activity, i m using StudioX. Is there any way to solve this without assing?

@Levente_Csontos_HU

Use set variable as

What is the format of the text file? Show us what’s in it.

The Item property of the activity is not an array. For Each is looping through the files, and each iteration of the loop the Item property represents the current file it’s on.

Change Item to CurrentFile. Then change your If condition to CurrentFile = value from the text file (which we still need to see).

However…

Assuming the text file is a CSV you want to use Read CSV to get it into a datatable. Then For Each Row in Datatable, and your if would be File.Exist(CurrentRow(“FileName”).ToString)

You’re trying to look at all the files and see if they’re in the text file. Do it the other way around. Loop through the filenames in the text file and if that file exists in the folder, copy it.

I m reading a txt file (notepad) and write it to a numbersList variable.

Show the content of the text file

image
the content

Hi @Levente_Csontos_HU

Try this

Read Text File
Use For each file in folder
if CurrentFile.Name.Contains(“numbersList”)
Copy file
Currentfile

or
use set variable as activity
Hope it helps!!

Use Read CSV to get it into a datatable. (or Read Text and then Generate Data Table)

For Each Row in Datatable

  • If File.Exists(Path.Combine(“C:\yourfolder”,CurrentRow(“Column1”).ToString)
    ** Copy Path.Combine(“C:\yourfolder”,CurrentRow(“Column1”).ToString)