How to get extensions from list of directory

Hi Every one,

I am getting a list of the files from the directory in the folder. How we can get the files extensions (.xlsx or xls or jpeg or pdf or docx) from the folder. Please find the attached screenshot for your reference. Could you pls help us with this scenario.


1 Like

Hello @Kiran When you say ‘you are getting list of files’ means I am assuming you are using ‘List Directory Files’ activity. When you use list directory files activity, result will be stored in directory_files variables which contains extensions along with filename.

1 Like

Thanks for responding. @Kudlappa_Gouder .
We are getting the same format in Variable. After getting the result we need to do some IF conditions based on the files format extensions. What i need to pass in IF condition (to get only PDF file). Pls refer to the screenshot.

1 Like

@Kiran You can use below IF statement
if(directory_files[i].indexOf(‘pdf’) !== -1)
You can loop through each file to find whether it contains pdf or not.

1 Like

@Kiran Let me know if above solution worked for you. Also mark this as a Solution

@Kudlappa_Gouder we are not getting using the above statment. Do you have a sample .neek file for this scenario. That will help me a lot.

@Kiran It’s not possible to share the .neek file in the forum. You can send me the value you are getting in the ‘directory_files’ variable(click on Show source value check box and send the Json format value) so I can give you the exact condition to use

Hi @Kudlappa_Gouder and @Kiran

I’m new to ElectroNeek and trying to find a way to check if Directory Files return results has any list of documents with extension “zip”. This is the output of the Directory Lists…

“1662595655472.Trans TRT2099.pdf”,

I tried to use DO While loop to iterate through list of documents but that didn’t work.

If you don’t mind, please guide or advise the best method to achieve the above.
Any help would be much appreciated.

1 Like

@g.melihov , @Fernanda_Costa , I think it’s a good area for future improvements. The task is straightforward (and common), but the way of solving is not super simple now. Take a look, please.


Hi @Kudlappa_Gouder

what you have provided the if condition. Getting some syntax error.

If possible, Send the screenshot for the process flow. That would help us.

Hi @Kiran_Yadavalli You are using the keyword “IF” again in the condition. Just remove it!

Now we are facing “i” variable issue. in attached screenshot we are not passing any variable. Kindly suggest where i need to pass variable.

Thanks @Kudlappa_Gouder I managed to get my flow working. I guess for this kind of small/common automation, it should be easy to configure. I’m now trying to understand the UNZIP and Move file activities. There’s a description for these activities under help but no examples. My workflow is failing to unzip the files to the predefined DIR location in a variable.

@Kiran_Yadavalli You need to write If condition within loop so that it will check each file to know whether it contains zip or not. Find the screenshot below.

If you are still facing the issue I would suggest you to contact support team(If in case you are missing some logic in the workflow, they can take a look and help you quickly).

1 Like

Hello @asharma I am guessing you are facing issue where you are using dynamic value of path. Try to use double slashes instead of single slash in the path
for example :
if variable pt = C:\Users\MUTTU\Downloads\Export then change it to below

I know I am assuming the issue :grinning: but this is the common mistakes I see while using dynamic paths.
You can give more information here to understand the issue if its not the above one.

Thanks @Kudlappa_Gouder for the path pointer. I did had double \ in the folder path VAR but it looks like it’s failing when unzipping the file. Getting “ENOENT: no such file or directory” error.
I’ll escalate it to support not sure what ENOENT means but thanks for your help. Just started playing with tool today and trying to build some concept of exporting attachments from mailbox and if there’s a zipped attachment , unzip it to location.

1 Like

@Yudovskiy , we will think about how we can improve our tool to handle such use cases better.
@Kiran , in the meantime, have you tried using this activity? File information – ElectroNeek Help Center

In that case your algorithm does not have to use that many JS calculations even if you are used to them. Just on each iteration, call the activity and do the if part.

In the meantime, if you are willing to use JavaScript for some reasons, it is also not necessary to use if for that. You can use an anonymous function like this:

const files = [
'1662595655472.Trans TRT2099.pdf',
(4) ['1662595655469.image001.png', '1662595655470.image404090.jpg', '1662595655472.Trans TRT2099.pdf', '1662595655473.Trans']

const zip_files = files.filter((file) => file.includes('.zip'))



@asharma , you might be interested in the above as well :slight_smile:

1 Like

This topic is very fascinating, but I agree with @Yudovskiy that this is a good area for future improvement because this task is definitely straightforward; however, the process for performing this is not. Every process needs to be streamlined so that the software is seen as extremely ideal for all situations. Additionally, as I know there is a technical writer on staff to enhance all aspects of training, these types of scenarios need to be fully captured in detailed steps with screenshots, etc. Love all of the feedback!

Hi @BrandonTerry, this is very valuable feedback. Thank you.