Loop through folder with sub-folders and upload all files - How to

yes, there is no need to to click and open the folder for your requirement.

@nadim.warsi

i have done till the point where i am getting all the file names and looping them.
I have added the filter too.

Please find the attached .xaml file for the same.

Well there is another file where i have done the recording of PDFSAM…

Please find both the files…
1.Pdfupload
Pdf upload.xaml (11.9 KB)
2.I have main file where the - PDFsam - ADD
pdfMerge.xaml (23.9 KB)

But i could not get how to pass the filtered file(YMKUL) 1st and all the other .pdf files too

Sonika

to find the files -Directory.GetFiles(item.ToString)

Can you send me this code xaml? Ill make my own directories and try it out

@nadim.warsi

i have done till the point where i am getting all the file names and looping them.
I have added the filter too.

Please find the attached .xaml file for the same.

Well there is another file where i have done the recording of PDFSAM…

Please find both the files…
1.Pdfupload
Pdf upload.xaml (11.9 KB)
2.I have main file where the - PDFsam - ADD
pdfMerge.xaml (23.9 KB)

But i could not get how to pass the filtered file(YMKUL) 1st and all the other .pdf files too

Sonika

1 Like

@nadim.warsi

Can you please help me with , how to implement the following points

  1. Get the list of files using filter not like MYKUL so you get the rest of the files
  2. Use invoke method to add file in point 1 to the top index 0 of the list

image

Kindly help me with this.

I have been trying… but i need your help…
If i created another .xaml. How shall i pass it to the pdf merge file…
also main thing is - 2 times how shall i pass the file path- i.e

  1. file path for - MYKUL
    2.for non MYKUL

these all files should be merged at one shot… Only thing is selection should happen 1st for - MYKUL file…

Regards,
Sonika

1 Like

Hello Sonika,

I have updated your workflow pdf upload.Pdf upload.xaml (18.5 KB)

Changes:

  1. Changed type of for each item /file to type String (you can do this in the properties pane, by default it is of type Object)
  2. Updated the logic i provided as we are using String, array of strings - cannot add dynamically in arrays
    … a. I am getting the list of files and looping through each
    … b. Then checking if the file name starts with MYKUL
    … c. Fetching the current Index if i get a match
    … d. if index already 0 then breaking the loop and continuing
    … d. else swapping element at 0 with index of MYKUL file

Hence you output String is same list but MYKUL at 0.

I have create an out argument that will allow the movement of the filelist out of this workflow
I have also created an in argument in pdfMergeandUpload, pdfUploadandMerge.xaml (23.9 KB)
which will take in the list of files
I have mapped the argument in the invoke workflow activity

Tweak, the workflow as i am not sure if i put the foreach in the correct place:
image

Hope it helps! :slight_smile:

1 Like

@nadim.warsi

Thnaks for the quick solution,

But i got one error while opening the file - its related to compatability issue…

Yes, :frowning: im at 2018.3.0

Not upgrading :stuck_out_tongue: ?

Oh Okay,

Yours is higher version, mine is 2018.2.4… No i cant upgrage :frowning:

Well can you please do one more help to me… Can you add the screen shot of the .xaml here… So that i can replicate the same on the .xaml

Thank you
Sonika

Here



image

Here is the flow

Assign - filename = Path.GetFileName(file)
Message box - file
If
filename.StartsWith(“MYKUL”)
Then
Assign - currIndex = Array.IndexOf(ListOfFileNm_in_Directory,file)
If
currIndex =0
Then
Break activity
Else
assign - ListOfFileNm_in_Directory(currIndex)= ListOfFileNm_in_Directory(0).ToString
assign - ListOfFileNm_in_Directory(0) = file
Break activity

In the for for each item in directories

end main add
assign - out_ListofFiles = ListOfFileNm_in_Directory first in argument tab create a arg out_ListofFiles of type array string and direction out
Invoke workflow - pdfUploadandMerger file

done :slight_smile:

Thanks Nadim,

The same thing happened with other file - PdfUploadandMerge.xaml.
So can you please add its screenshots too…

done :slight_smile:

@nadim.warsi

I have replicated the same code in uipath.

But i got the following error- i dont no where i went wrong. Please check below screen shot

I have add

also i could not understand clearly these both assign activities , can please help me to understand these 2.
In the Assign activity

ListOfFileNm_in_Directory(currIndex)= ListOfFileNm_in_Directory(0).ToString — here (0) is mentioned so is it the 1st file??

ListOfFileNm_in_Directory(0)(currIndex)=file - I could not get this

and in below screen shot
image
where did i go wrong, i feel i am missing something??

also for the invoke workflow file - i have to pass the argument - “out_ListofFiles” in ImportArgument?
image

Regards,
Sonika

Mistake is here.
It should be

Swapping logic:

I am swapping the top element with MYKUL element
so for that,
first i am moving top element( which is at 0) to MYKUL index (which is at current index)
and then placing MYKUL elememt to top (0)

For below:
image
dont use just put the variable name ListOfFileNm_in_Directory

Import Argument is in simple terms to pull out the arguments that are defined in the workflow (sometimes when you update or add new ones)
And to pass the values, you can click on Edit Arguments

image

1 Like

@nadim.warsi

I am getting “null” values for the argument…

As shown in screenshot


i am not getting why is it showing null… Also the argument is of type - System.String.

Can you please check it.

Regards
Sonika

Can you show me the screenshot of your Edit Argument?
Argument type will be Array of type String [In the type select array and then set the type in next option to string]

@nadim.warsi

The null value i am getting is from the - Assign activity.
image
Though there is a value in the variable - ListOffileMn_in_Directory the argument - out_ListofFiles is showing null :frowning:

Well in the Invoke workflow file - i have not executed yet.

Sure here is the screenshot of - Edit arguments…

Ok.
I got what you are saying.
What is on the right side of your assign? is it just the variable name or you have kept something after that?

Also, i believe that the next workflow has out_ListofFiles as an in argument
if yes, suggest you to rename it to in_ListofFiles and then import again and after that on the right side put out_ListofFiles variable to bind them together