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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Automate
Answered

Creating a flow

(0) ShareShare
ReportReport
Posted on by 108

Hi Everyone, 

 

i am new to this amazing app. i have to download 7 text files everyday, and the file's name will be different every time. 

if i want it to sort smallest numbers of the file name to largest numbers of the file name, and then copy all data from the top 4 text file, past it to the first sheet of excel. after that copy the data from the bottom 3 text file and past in to the second sheet of excel. how can i do this with power automate?

 

pls help me with it, many many thanks

 

rrrradfafwgvafv_0-1714917522860.png

 

I have the same question (0)
  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @rrrradfafwgvafv 

     

    Please follow the below approach for your use case:

    Deenuji_0-1714930384285.png

    Deenuji_1-1714930413658.png

    Deenuji_2-1714930430211.png

     

    While using "Get files in folder" action use sort function as like below:

    Deenuji_5-1714930668766.png

     

    Code:

    Folder.GetFiles Folder: $'''C:\\Boot\\txt''' FileFilter: $'''*txt''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.Name SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    SET File_Name1 TO Files[0].Name
    Text.GetSubtext.GetSubtext Text: File_Name1 CharacterPosition: 19 NumberOfChars: 3 Subtext=> File_Name1
    SET File_Name4 TO Files[3].Name
    Text.GetSubtext.GetSubtext Text: File_Name4 CharacterPosition: 19 NumberOfChars: 3 Subtext=> File_Name4
    SET Sheet1 TO $'''Sales %File_Name1 + '-' + File_Name4%'''
    SET File_Name5 TO Files[4].Name
    Text.GetSubtext.GetSubtext Text: File_Name5 CharacterPosition: 19 NumberOfChars: 3 Subtext=> File_Name5
    SET File_Name7 TO Files[6].Name
    Text.GetSubtext.GetSubtext Text: File_Name7 CharacterPosition: 19 NumberOfChars: 3 Subtext=> File_Name7
    SET Sheet2 TO $'''Sales %File_Name5 + '-' + File_Name7%'''
    SET Counter TO 0
    Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance
    Excel.AddWorksheet Instance: ExcelInstance Name: Sheet1 WorksheetPosition: Excel.WorksheetPosition.First
    Excel.AddWorksheet Instance: ExcelInstance Name: Sheet2 WorksheetPosition: Excel.WorksheetPosition.Last
    LOOP FOREACH CurrentItem IN Files
     IF Counter <= 3 THEN
     File.ReadTextFromFile.ReadTextAsList File: CurrentItem.FullName Encoding: File.TextFileEncoding.UTF8 Contents=> FileContents
     Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: Sheet1
     Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: FileContents Column: $'''A''' Row: FirstFreeRow
     END
     IF Counter > 3 THEN
     File.ReadTextFromFile.ReadTextAsList File: CurrentItem.FullName Encoding: File.TextFileEncoding.UTF8 Contents=> FileContents
     Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: Sheet2
     Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: FileContents Column: $'''A''' Row: FirstFreeRow
     END
     SET Counter TO Counter + 1
    END

     

    Output:

    Deenuji_4-1714930600136.png

     

    How to copy/paste the above code into your power automate desktop?

    Deenuji_3-1714930506959.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 🚀

  • rrrradfafwgvafv Profile Picture
    108 on at

    can i just paste the data of first 4 files in the original sheet of Excel, instead of adding new sheet?

  • Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @rrrradfafwgvafv 

     

    My apologies. Could you please elaborate what you want to accomplish now?

  • rrrradfafwgvafv Profile Picture
    108 on at

    you can see in your "output" picture, there is a "sheet 1" with no data inside it. can i paste data into "sheet 1" in the beginning?

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @rrrradfafwgvafv 

    Yes that’s feasible only. What data you would like to paste there?

  • rrrradfafwgvafv Profile Picture
    108 on at

    data from top 4 text file, paste it to the sheet1 of excel. after that, copy the data from the bottom 3 text file and paste to the sheet2

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @rrrradfafwgvafv 

     

    Please follow the below approach:

    Deenuji_0-1715189464570.png

    Deenuji_1-1715189521306.png

     

    Code:

     

    Folder.GetFiles Folder: $'''C:\\Boot\\txt''' FileFilter: $'''*txt''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.Name SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    SET Counter TO 0
    Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance
    Excel.AddWorksheet Instance: ExcelInstance Name: $'''Sheet2''' WorksheetPosition: Excel.WorksheetPosition.Last
    LOOP FOREACH CurrentItem IN Files
     IF Counter <= 3 THEN
     File.ReadTextFromFile.ReadTextAsList File: CurrentItem.FullName Encoding: File.TextFileEncoding.UTF8 Contents=> FileContents
     Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: $'''Sheet1'''
     Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: FileContents Column: $'''A''' Row: FirstFreeRow
     END
     IF Counter > 3 THEN
     File.ReadTextFromFile.ReadTextAsList File: CurrentItem.FullName Encoding: File.TextFileEncoding.UTF8 Contents=> FileContents
     Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: $'''Sheet2'''
     Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: FileContents Column: $'''A''' Row: FirstFreeRow
     END
     SET Counter TO Counter + 1
    END

     

     


    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 🚀

  • rrrradfafwgvafv Profile Picture
    108 on at

    Hi Sir, 

    if I manually copy the data from .txt and paste to excel, data will be separately pasted in different columns

    q1.png

     

    However, when i try to run the program, the data will only be pasted in the first column of excel

    q2.png

    Is there any way to fix this?

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @rrrradfafwgvafv 

     

    Please follow the below approach:

    Deenuji_0-1715792014243.png

     

    Code:

    File.ReadTextFromFile.ReadTextAsList File: $'''C:\\Boot\\Numbers.txt''' Encoding: File.TextFileEncoding.UTF8 Contents=> FileContents
    Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance
    SET ExcelRowCounter TO 1
    LOOP FOREACH CurrentItem IN FileContents
     Text.SplitText.Split Text: CurrentItem StandardDelimiter: Text.StandardDelimiter.Tab DelimiterTimes: 1 Result=> TextList
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: TextList[0] Column: $'''A''' Row: ExcelRowCounter
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: TextList[1] Column: $'''B''' Row: ExcelRowCounter
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: TextList[2] Column: $'''C''' Row: ExcelRowCounter
     SET ExcelRowCounter TO ExcelRowCounter + 1
    END

     

     


    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 🚀

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 796

#2
Valantis Profile Picture

Valantis 568

#3
Haque Profile Picture

Haque 538

Last 30 days Overall leaderboard