Match file name and move

Hello friends,
@rkelchuri, @Ninett_Panfir, @Rammohan91, @balupad14, @Florent_Salendres, @vvaidya, @Palaniyappan, @ClaytonM, @vvaidya

I need to check if in a folder there are two files with the same name but with two different extensions (.xml and pdf).
How to perform this check?
In case there only one of the two I should move the file which hasn’t got the match.
Can you please help me in giving me a workflow?
Thank you,
Cami

1 Like

Hi @CamiCat

Strfiles=Directory.getfiles(inputffilepath)

Use path exists and pass the strfiles

And conditions are true

Use move file activity

Thanks
Ashwin.S

1 Like

Hi Cami
@CamiCat
In reference to this topic

With the following comment
— inside the loop use a if condition like this
Outxmldilepath.Contains(path.GetFilenameWithoutExtension(item.ToString))
If the above condition passes it will go rot THEN part which means there is similar filenamed files
Which we can mention In a message box activity
If not will go to ELSE part where we can mention no similar named files in a message box

Here in the ELSE part we can use a move file activity with source file property as item and mentio the destination folder to the path where you want to move

Hope this would help you
Cheers @CamiCat

2 Likes

What about it you want to match a files name to the folder and move but part of the file name will constantly change and the folders as well. For example if I have file is 1G23A and the folder is the same. The alphanumeric part will change. How can I incorporate it to an activity?

I think it should work.

Directory.GetFiles(FolderPath, “.”, SearchOption.AllDirectories).Where(Function(s) s.EndsWith(“.pdf”) Or s.EndsWith(“.xml”))

That will not work because I need to match a specific alphanumeric text within the file. It doesn’t matter about the extension. For example. I have a file named student_a1bcde_2019 and i have a folder with the following name Class123_student_a1bcde_2019. The a1bcde will always be changing because it is an id and unique to the user. I can match the pattern with regex but how do I match a file to the folder and move it if the condition is met. I have no clue and I am stuck

Hello!

Would this work to move two files if the name is the same but with different extension?

Hi @Beatriz_Eugenia_Duqu

as per the @anandji05 way , it will filter the files with the given extension , and u can store the result in a array. Then u can iterate through each files and inisde it use move file activity to move the file

Regards,
Nived N
Happy Automation

1 Like

Hi @Beatriz_Eugenia_Duqu - Below one line copy all the .pdf and .xml files to the destination

image

array.ForEach(Directory.GetFiles("DeleteFiles\", “*”, SearchOption.AllDirectories).Where(Function(s) s.EndsWith(".pdf") Or s.EndsWith(".xml")).ToArray,Sub(x) File.Copy(x,"MoveFiles\"+ Path.GetFileName(x)))

Above code copy the files from DeleteFiles folder to MoveFiles folder…

2 Likes