I have a process that generates some files that are saved in folder 1 I have to validate if the files generated are any that exist in folder 2, if this is true I have to delete them and only pass the files that are not repeated in any of the two folders to generate folder 3
I appreciate if anyone can help me with this issue.
Hi
You were almost done
The sequence be like this
—use two assign activity like this
Files1 = array of files in folder 1
Files2 = array of files in folder 2
—use another two assign activity like this list_var = Files1.ToList() list_other = Files2.ToList()
—now use a FOR EACH activity and pass the above variable list_other as input and change the type argument as string in the property panel of for each loop
—inside the loop use a IF condition like this list_var.Contains(item.ToString)
If true it will go to THEN part where use a DELETE activity and mention like this item.ToString
THUS MATCHING file and its file path will get deleted in variable list_other
Now next to this for each loop use a CREATE DIRECTORY ACTIVITY and create a folder with a folder path
—now use a FOR EACH LOOP and pass the variable list_other as input and change the type argument as string in the property panel of for each loop
—inside the loop use MOVE FILE activity where in the path mention as item.ToString and in the destination property mention the folder path of new folder created with CREATE DIRECTORY activity
As the file names are already Stored in list, the calculations can even realized with the Set functions (e.g union, except etc). So WE can quickly calculates such delete or move Liste as well and very directly
You dont need foreach to find the files, only to delete them, see if this examples help you get the idea:
Dim A() As String = {"Hello", "How", "Are", "You?"}
Dim B() As String = {"You", "How", "Something Else", "You"}
Console.WriteLine("A elements not in B: " + String.Join(", ", A.Except(B)))
Console.WriteLine("B elements not in A: " + String.Join(", ", B.Except(A)))
Console.WriteLine("Elements in both A & B: " + String.Join(", ", A.Intersect(B)))
*** EDIT
Also i need to remind you that you are using full paths to compare the files, so they will never be the same
I debuted and found that the item that uses the for each has only “/” instead list_other has “//” I don’t know if this affects when making the comparison
Wasn’t sure if you intend to delete from folders 1 and 2 but try something like this.
folder1 = directory.GetFiles("folder1").toList
folder2 = directory.GetFiles("folder2").toList
folder2path = path.GetDirectoryName("folder2")
For Each file In folder1
checkFolder2File = folder2path & "\" & path.GetFileName(file)
If folder2.contains(checkFolder2File) Then
delete file
delete checkFolder2File
Else
copy file To folder 3
End If
Next
When you use the For Each activity, make sure you change the type from Object to String in the properties.
May not be exactly what you’re looking for but you’ll get the idea.
I generated two cycles one to read the files in folder 1 and another one to read folder 2. I split the routes and obtained the name of the file in a String. Now to make the comparison I use an Equals to validate if applicable or not with the file in the other folder and I delete the file PAth: item.ToString. Note: I remove the break to continue the cycle until it goes through all the files and eliminates the duplicates.
Thanks to everyone they helped me a lot with the subject.