Hi I'm quite new to power automate please help me.
I need to merge 2 files that have the same name but from different folder. And then rename the merge file with the same name in a different folder
Most tutorial shows how to merge many files from 1 folder so I'm blank.
Hi @Hasya
My requirement is similar to your case.
Select the files in SharePoint from folder A and folder B and folder C based on file name and merge into single pdf and saved the merged PDF into folder D with the name of file name in Power automate.
if you have solution please help me on this
Thank you alll all the tips arevery helpful. my flow now work just fine 😁
I think the problem there is now two lists inside a list and PDF files input is expecting one list/array.
Since MergeFile1 and MergeFile2 are arrays and they are surrounded by %[]% array syntax.
So if you put %[MergeFile1[0], MergeFile2[0]]% then it should work since its taking first item from both lists and not whole list from both variables.
And as you said you one two pdfs to be merged and not every pdf from both folders into one file.
So you need to loop the MergeFile lists and merge them one by one. I made example flow assuming the folder lists have the exact same files in same order.
Folder length conditions are for checking is one of the folders has more files and there for loop doesn't go in to error.
PDF action:
I couldn’t get the syntax to work either, that’s why I opted to use a list.
create the list first, before the 1st loop, then clear the list in the first loop, and use the “add to list” to add each file, then merge the list together.
i doesn't seem to work for me any idea why?
i use %[MergeFile1,Mergefile2]%
I actually just set this up for a client:
The parts I didn't share:
Variables.CreateNewList List=> FilesToMerge
SET pdfFilesPath TO $'''C:\\Users\\micha\\OneDrive - Peak Digital Transformations LLC\\Documents\\Clients\\Forge\\Audit\\Saved PDF Files'''
SET pdfFilesPathSchedules TO $'''C:\\Users\\micha\\OneDrive - Peak Digital Transformations LLC\\Documents\\Clients\\Forge\\Audit\\Saved PDF Files\\Schedules'''
SET pdfFilesPathNotes TO $'''C:\\Users\\micha\\OneDrive - Peak Digital Transformations LLC\\Documents\\Clients\\Forge\\Audit\\Saved PDF Files\\Notes'''
SET pdfFilesPathMerged TO $'''C:\\Users\\micha\\OneDrive - Peak Digital Transformations LLC\\Documents\\Clients\\Forge\\Audit\\Saved PDF Files\\Merged'''
Create New List -> FilesToMerge
Set Folder1 (I had it as pdfFilesPathSchedules)
Set Folder2 (I had this as pdfFilesPathNotes)
Set MergeFolder (I had this as pdfFilePathMerged)
So, this basically reads all the files from the first folder and only merges them if there is matching file in the second folder.
Hope this helps.
Here is the code for lines 6 and on...I don't want to share the folder variables...don't forget to create the list up front:
Folder.GetFiles Folder: pdfFilesPathSchedules FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
LOOP FOREACH PDFSchedule IN Files
Variables.ClearList List: FilesToMerge
SET PDFNotes TO $'''%pdfFilesPathNotes%\\%PDFSchedule.Name%'''
Variables.AddItemToList Item: PDFNotes List: FilesToMerge
Variables.AddItemToList Item: PDFSchedule List: FilesToMerge
IF (File.IfFile.DoesNotExist File: PDFNotes) THEN
NEXT LOOP
END
# If PDFNotes doesn't exist, skip
SET PDFMerged TO $'''%pdfFilesPathMerged%\\%PDFSchedule.Name%'''
Pdf.MergeFiles PDFFiles: FilesToMerge MergedPDFPath: PDFMerged IfFileExists: Pdf.IfFileExists.Overwrite PasswordDelimiter: $''',''' MergedPDF=> MergedPDF
File.Move Files: PDFSchedule Destination: $'''%pdfFilesPathSchedules%\\Processed''' IfFileExists: File.IfExists.Overwrite MovedFiles=> MovedFiles
File.Move Files: PDFNotes Destination: $'''%pdfFilesPathNotes%\\Processed''' IfFileExists: File.IfExists.Overwrite MovedFiles=> MovedFiles
END
Good luck!
I think you don't even need to have double \ (so forget what I first suggested)
I got it to work like this without problems with variables:
Can you share screenshots of how your flow looks and the error you get
Thank you it's very informative. I tried using that for variable but I doesn't work. I need the file from many different folders. So I would be helpful to have easy option to change.
Try it like this:
So put the file paths inside %[]%
%['pdfPath1', 'pdfPath2']%
and in the PDF files change the \ to be double \\
Thats how I got it to work atleast.
WarrenBelz
146,743
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,079
Most Valuable Professional