web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / how to combine pdf fil...
Power Automate
Answered

how to combine pdf files from folder A and folder B and put them into folder C

(0) ShareShare
ReportReport
Posted on by 24

because of the workload and I found automation using PAD, here I want to combine the pdf files from folder A and folder B then put them into folder C. in the order of pdf files from folder A above and pdf files from folder B below
The following is an illustration of the contents of folder, folder B, and folder C

Folder A
1234_SEP.pdf
1235_SEP.pdf
etc

 

folder B
1234.pdf
1235.pdf
etc

 

C folder
with the new file name 1234.pdf (1234_SEP.pdf above and 1234.pdf below)

 

I hope that makes sense, Thanks in advance for your help

I have the same question (0)
  • VishnuReddy1997 Profile Picture
    2,656 Super User 2025 Season 2 on at

    Hi @lagibingung ,

     

    Please find the below solution.

    Combine2.pngCombine1.png

    Dynamically If you want to loop for multiple files. Please find the below solution.

     

    VishnuReddy1997_1-1711035905658.png

     

     

    Code:

     

    Folder.GetFiles Folder: $'''C:\\Users\\OneDrive\\Desktop\\Power Automate Desktop\\Practice\\Combine PDFS\\Folder A''' FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> FolderA_Files
    Folder.GetFiles Folder: $'''C:\\Users\\OneDrive\\Desktop\\Power Automate Desktop\\Practice\\Combine PDFS\\Folder B''' FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> FolderB_Files
    SET Counter TO 0
    LOOP FOREACH CurrentItem IN FolderA_Files
    Pdf.MergeFiles PDFFiles: $'''{ \"%FolderA_Files[Counter].FullName%\", \"%FolderB_Files[Counter].FullName%\" }''' MergedPDFPath: $'''C:\\Users\\OneDrive \\Desktop\\Power Automate Desktop\\Practice\\Combine PDFS\\Folder C\\MergedPDF.pdf''' IfFileExists: Pdf.IfFileExists.AddSequentialSuffix PasswordDelimiter: $''',''' MergedPDF=> MergedPDF
    Variables.IncreaseVariable Value: Counter IncrementValue: 1
    END

     

    (Note:- if you got your solution you can mark as solution and gives kudos)

     

    Thanks & Regards

    Vishnu Reddy

  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @lagibingung 

     

    So, if I understand correctly, you're looking to find files with similar names in different folders. For instance, in the first folder, you have a file named "1234_Sep.pdf", and in another folder, say folder B, there's a file named "1234.pdf" (without "Sep").

     

    If such files exist, do you want to combine them? Am I getting it right?


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏

     
     
  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @lagibingung 

    Please find the below step by step guide to achieve your goal.

     

    1. **Get Files from Folder A**:
    - Configure your folder A. For an instance I am choosing my folder name as "C:\User\Folder A".
    - Set the variable `AFolderFiles` to store the list of files.

    2. **Get Files from Folder B**:
    - Configure your folder B. For an instance I am choosing my folder name as "C:\Deenu\Folder B".
    - Set the variable `BFolderFiles` to store the list of files.

    3. **Count Files in Each Folder**:
    - Count the number of files in folder A and store the count in the variable `FileCountAFolder`.
    - Count the number of files in folder B and store the count in the variable `FileCountBFolder`.

    4. **Check File Counts**:
    - Compare the file counts of folder A and folder B.
    - If the counts are equal, proceed; otherwise, the process stops here.

    5. **Merge Files with Similar Names**:
    - Initialize a counter variable `Counter` to 0.
    - Start a loop iterating from 0 to `FileCountAFolder - 1`.
    - Split the names of files in folder A and folder B by underscores and periods respectively to extract the base file names.
    - Compare the base file names from folder A and folder B.
    - If the base file names match, merge the corresponding PDF files from both folders into a single PDF file.
    - Save the merged PDF file in "C:\Deenu\Folder C" with the base file name.
    - If a merged PDF file with the same name already exists, add a sequential suffix.
    - Increment the counter variable by 1 after each iteration.
    - Continue the loop until all files in folder A are processed.

     

    Flow Screenshot:

    Deenuji_0-1711037473693.png

    Deenuji_1-1711037495278.png

     

     

    Code:

     

    Folder.GetFiles Folder: $'''C:\\Deenu\\Folder A''' FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> AFolderFiles
    Folder.GetFiles Folder: $'''C:\\Deenu\\Folder B''' FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> BFolderFiles
    SET FileCountAFolder TO AFolderFiles.Count
    SET FileCountBFolder TO BFolderFiles.Count
    IF FileCountAFolder = FileCountBFolder THEN
     SET Counter TO 0
     LOOP LoopIndex FROM Counter TO FileCountAFolder - 1 STEP 1
     Text.SplitText.SplitWithDelimiter Text: AFolderFiles[Counter].Name CustomDelimiter: $'''_''' IsRegEx: False Result=> FileNameAList
     Text.SplitText.SplitWithDelimiter Text: BFolderFiles[Counter].Name CustomDelimiter: $'''.''' IsRegEx: False Result=> FileNameBList
     IF FileNameAList[0] = FileNameBList[0] THEN
     Pdf.MergeFiles PDFFiles: $'''{ \"%AFolderFiles[Counter].FullName%\", \"%BFolderFiles[Counter].FullName%\" }''' MergedPDFPath: $'''C:\\Deenu\\Folder C\\%FileNameAList[0]%.pdf''' IfFileExists: Pdf.IfFileExists.AddSequentialSuffix PasswordDelimiter: $''',''' MergedPDF=> MergedPDF
     END
     Variables.IncreaseVariable Value: Counter IncrementValue: 1
     END
    END

     

     

    How to copy and paste the above code into your desktop flows?

    Deenuji_2-1711037585992.gif


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏

     
  • lagibingung Profile Picture
    24 on at

    i have problem

    lagibingung_4-1711038171875.png

     

    lagibingung_0-1711037970280.pnglagibingung_1-1711038002779.pnglagibingung_2-1711038037760.pnglagibingung_3-1711038123492.png

     

  • lagibingung Profile Picture
    24 on at

    yess, that right

  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @lagibingung 

     

    Ok please try the above suggested approach. I have explained step by step process also. Please check

     
  • VishnuReddy1997 Profile Picture
    2,656 Super User 2025 Season 2 on at

    Hi @lagibingung ,

     

    In Get files in Folder action,you have given wrongly in Filter criteria.

    Please give as below shown in image.It will solve the issue or copy the below code mentioned from first reply of mine and paste it in your flow and just change the folder paths.

    VishnuReddy1997_0-1711038486207.png

    (Note:- if you got your solution you can mark as solution and gives kudos)

     

    Thanks & Regards

    Vishnu Reddy

     

  • lagibingung Profile Picture
    24 on at

    I have copied your script, and there is no error there, but in the output folder the merged PDF does not appear

  • lagibingung Profile Picture
    24 on at

    lagibingung_0-1711039422907.pnglagibingung_1-1711039444438.png

     

  • VishnuReddy1997 Profile Picture
    2,656 Super User 2025 Season 2 on at

    Hi @lagibingung ,

     

    Did you copied my code or  @Deenuji  code.

    If you have copied @Deenuji  code ,Please try my code once and let me know.

     

    (Note:- if you got your solution you can mark as solution and gives kudos)

     

    Thanks & Regards

    Vishnu Reddy

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard