File name

I am using an expression to process only specific files form a folder but i want to process only the files which start with PAN_, CHEQUE_, GST_ Can anyone please help me with this?
Below are the screenshots


Hi @Seema_Jethe ,

try below code
Directory.GetFiles(@"c:\MyDir", “PAN_", SearchOption.AllDirectories)
Directory.GetFiles(@"c:\MyDir", "CHEQUE_
”,SearchOption.AllDirectories)
Directory.GetFiles(@"c:\MyDir", “GST_*”, SearchOption.AllDirectories)

or

Directory.GetFiles("C:\\MyDir", "*.*", SearchOption.AllDirectories)
            .Where(s => s.StartWith("PAN_") || s.StartWith("CHEQUE_") || s.StartWith("GST_"))

Regards,
Arivu

1 Like

@arivu96 Can this be used in one expression only?

Try this
Directory.GetFiles("C:\\MyDir", "*.*", SearchOption.AllDirectories) .Where(s => s.StartWith("PAN_") || s.StartWith("CHEQUE_") || s.StartWith("GST_"))

Regards,
Arivu

@arivu96 i tried using your code but it has some error
below is the ss

Hey @Seema_Jethe, Please use that expression in one single line.

try this in single line
Directory.GetFiles(“C:\MyDir”, “.”, SearchOption.AllDirectories) .Where(s => s.StartsWith(“PAN_”) || s.StartsWith(“CHEQUE_”) || s.StartsWith(“GST_”))

@Seema_Jethe ,

Try this:

Assign Activity:

strArrVariable = Directory.GetFiles(“FolderPath”, “.”, SearchOption.AllDirectories).Where(function(s) path.GetFileName(s).StartsWith(“PAN_”) and path.GetFileName(s).StartsWith(“CHEQUE_”) and path.GetFileName(s).StartsWith(“GST_”) and s.EndsWith(“.pdf”) and s.EndsWith(“.jpg”)).ToArray

Thanks!

@arivu96 i have used the expression in single line but it still has error

@kadiravan_kalidoss i tried your expression but it does not work i am getting null value in variable using assign activity

Hi @Seema_Jethe ,

Can you send the error message.

Regards,
Arivu

@arivu96 Below is the ss

Hello @arivu96

You used where() function. Is part of a LINQ command ?

Thanks in advance/

Try below code
VB.net
Directory.GetFiles("C:MyDir", ".", SearchOption.AllDirectories).Where(Function(s) s.StartsWith("PAN_") OrElse s.StartsWith("CHEQUE_") OrElse s.StartsWith("GST_"))
or
c#
Directory.GetFiles("C:\MyDir", ".", SearchOption.AllDirectories) .Where(s=> s.StartsWith("PAN_") || s.StartsWith("CHEQUE_") || s.StartsWith("GST_"));

Regards,
Arivu

@arivu96 I tried your expression but it does not work the variable value is null

Hi @Seema_Jethe ,

Try the below expression. it was working at my end. thanks.

Hi,

Try with the below expression. it was working at my end.

Expression.txt (170 Bytes)

2 Likes

@kirankumar.mahanthi1 will your expression process the files starting with PAN_ , CHEQUE_, GST_ as i need only the files with names as PAN_xx.pdf or jpg, CHEQUE_xx.pdf or jpg or GST_xx.pdf or jpg and not files like xxx_PAN.pdf or jpg

i have tried with few samples only. Could you test with your files in Realtime and let us know. thanks.

Hi @Seema_Jethe,

I have modified the condition and tested. Its working as expected. Please try this code below.

StringArrayVariable = Directory.GetFiles(“FolderPath”, “.”, SearchOption.AllDirectories).Where(function(s) (path.GetFileName(s).StartsWith(“PAN_”) or path.GetFileName(s).StartsWith(“CHEQUE_”) or path.GetFileName(s).StartsWith(“GST_”)) and (s.EndsWith(“.pdf”) or s.EndsWith(“.jpg”))).ToArray

Thanks!