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?
Can you please help me in giving me a workflow?
Thank you,
Cami
@CamiCat do you want to work with these two files or only one.if it is one you can give like this directory.getfiles(“path of the folder”,“*.pdf”) if it is xml replace pdf with xml
Fine
Hope these steps could help you resolve this
— use assign activity like this Outpdfilepath = Directory.GetFiles(“yourfolderpath”, ”*.pdf”)
And another assign activity like Outxmldilepath = Directory.GetFiles(“yourfolderpath”, ”*.xml”)
Where Both the variables are string array
— next use a for each loop and pass the first variable Outpdfilepath 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 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
Simple isn’t it
Hope this would help you
Cheers @CamiCat
If the abo
Sounds like you want to check for duplicates, then do something with it.
Just a simple idea here, but you could get all files for each extension like palaniyappan said, then run them through a loop and match it by the filename to see if it is in both. There’s probably another efficient way, but my brain is not having it.
filesPDF = Directory.GetFiles(folderPath, "*.pdf").Select(Function(f) Path.GetFilenamewithoutextension(f) )
filesXML = Directory.GetFiles(folderPath, "*.xml").Select(Function(f) Path.GetFilenamewithoutextension(f) )
For each f in filesPDF //TypeArgument String
If filesXML.Contains(f)
<do something with f + ".pdf" or f ".xml" extension>
@CamiCat this will give you an array of string variables that are duplicates.
First create a string array variable I’ll call arrFiles and assign arrFiles = Directory.Getfiles(YourDirectory,"*.*").Where(Function (x) x.EndsWith(".pdf") OrElse x.EndsWith(".xml")).ToArray
For Each file in arrFiles, assign file = Path.GetFileNameWithoutExtension(file)
After For Each loop from step 2 is finished, create another string array variable i’ll called arrDuplicateFiles and assign arrDuplicateFiles = arrFiles.GroupBy(Function(x) x).Where(Function(y) y.Count() > 1).Select(Function(y) y.First).ToArray
Now you have an array of strings that are duplicate file names for .xml and .pdf extensions. You can process them as needed within a for each string activity
Alternative to Step 2 instead of using GroupBy you could just use 2 Where statements instead: Assign arrDuplicateFiles = arrFiles.Where(Function(x) arrFiles.Where(Function(y) x = y).Count() > 1).Distinct().ToArray
how in case there is a xml file without the pdf ?
inside the loop use a if condition like this Outxmldilepath.Contains(path.GetFilenameWithoutExtension(item.ToString))
only works if there is a pdf
Thank you.
Cami
That’s a good question
But this expression usually validate only there is a match or not
If there is a match we would get message like “MATCHES”
If not “NO MATCHES”
Whether there is pdf file or not or only XML is there it doesn’t matter
Simple isn’t it
Hope this would help you
cheers @CamiCat