How to write directory.getfile with "not contains" criteria

Hello evrybody !

I need help to write a code.

I don’t know, and i haven’t find how to use correctly the expression directory.getfile
Actualy, i use it like that =>

Directory.GetFiles( Sousrep,"*.PDF")

Where SousRep , is my folders names. SO my Variables take all the .pdf in a folder.
Then i Use “Join pdf file”, to join evry pdf file in one.

My difficulty is =>

I want to exclude from the join activity, files with file names contains “_validé.pdf” or “justificative.pdf”

TO join in one file all the files if there names isn’t “pièce justificative.pdf” or “***_validé.pdf”

I hope you will understand my sollicitation ^^

Thanks you for your help !

Manoss

Hi there @manu_debonne,
Interesting question and unfortunately, not one I have a perfect answer for.

As far as I am aware, you cannot exclude items from the GetFiles.
With that said, you can absolutely filter the results to exclude anything you want, as shown below:
Assign - strMyDirectory = "C:\Sousrep"
Assign - arrFilesToExclude = New String(1){"_validé.pdf", "“justificative.pdf”}
Assign - arrFiles = Directory.GetFiles(strMyDirectory, "*.pdf")
Assign - arrFiles = arrFiles.AsEnumerable().Where(Function (strFileName) Not(arrFilesToExclude.AsEnumerable.Any(Function (strFileToExclude) Path.GetFileName(strFileName).Contains(strFileToExclude)))).ToArray

The results of the above should be your Array of files, without any you require excluded.
Hopefully this helps!
Thanks in advance,
Josh

hey Mr_JDAVEY,

You know whats? It’s works perfectly !

Thanks you a lot for the astuce

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.