Assign filenames to variables in for each

excel
file

#1

Hi All ,

I am trying to see if there is a way to get all the file names from a folder and assign it to different variables,

E.G -> Folder A has 5 files , I want to get the name of these files and store it to variables file1,file2 etc.

Is this doable.


#2

Hi @saivig,

Use this > Directory.GetFiles(Path,".",SearchOption.Alldirectories) - To get all files in folders and subfolders

The output of it will be an array and then you can loop through the array to either use them directly or assign it to the variables and then work.

Regards,
V


#3

@Vikas.Jain

I tried the following got the directory , how do I assign variable file names in a for each loop


#4

Test.xaml (6.8 KB)


#5

Hey @saivig

You can file name like this : string fileName = Path.GetFileName(item)
and in your workflow foreach argument should be string.

Test.xaml (6.8 KB)

Regards…!!
Aksh


#6

Thanks @aksh1yadav . I want to pass these as variable like name1 for the first , name 2 etc.

I tried introducing an int in the assign ( like name + int2) and increment int but that did not work


#7

Test (1).xaml (7.9 KB)

This is why I need the file names , Unless I pass the file name in the attach for the outlook the outlook only sends back 1 file.

I want to send 1 mail with all the files attached.


#8

I don’t think you can create variables on the fly. you can use in a below way

update : modified

Dictionary1.xaml (9.5 KB)


#9


#10

Do you have this package installed?


#11

Dictionary1.xaml (9.5 KB)


#12

Well it is not directly possible to use values like this in L-value expression but you can use string collection and then useing counter assign that name with counter into that collection then you will be able to use that collection names as a variable.

For more info see this attached workflow and let me know. For me it is working well.
Dynamic_variable_name_sample.xaml (8.2 KB)

Regards…!!
Aksh


#13

I am just curious can we invoke the powershell , list all the files under a folder and pass it as a variable from there.


#14

Yes we can :slight_smile:

please find attached workflow for your reference: invoke_powershell_to_fetch_directory_files_into_dynamic_variables.xaml (11.3 KB)

Regards…!!
Aksh