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 Platform Community / Forums / Power Automate / File rename with 01,02...
Power Automate
Answered

File rename with 01,02,03....10,11,12 possible? (Not 1,2,3....)

(0) ShareShare
ReportReport
Posted on by 112

Hi guys. 

We are supposed to rename multiple files with 

#vendor code_vendor name_ddMMyy_01

#vendor code_vendor name_ddMMyy_02

#vendor code_vendor name_ddMMyy_03

 

Is it possible to rename with 01,02,03...10,11,12...?

 

In my Desktop flow

1.Change a file name to "_number"

2.Add ddMMyy

3.Add #vendor code_vendor name_

file rename.jpgfile rename2.jpg

But I can't find any idea to change 01,02,03....

I have the same question (0)
  • ryule Profile Picture
    929 Super User 2024 Season 1 on at

    This code takes the files in the folder and renames them all with the date and adds the 0 in front of the number if necessary. I'm not sure how you are pulling vendor code and name, but you could easily throw those into this as well.

     

    Folder.GetFiles Folder: $'''\\\\server\\genactg\\SHARED\\RPA\\TEST''' 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
    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''_ddMMyy''' Result=> FormattedDateTime
    LOOP FOREACH CurrentItem IN Files
    Variables.ClearList List: Positions
    File.GetPathPart File: CurrentItem.FullName FileNameWithoutExtension=> FileNameNoExtension
    Text.ParseText.Parse Text: FileNameNoExtension TextToFind: $'''_''' StartingPosition: 0 IgnoreCase: False OccurrencePositions=> Positions
    LOOP FOREACH CurrentItem2 IN Positions
    SET LastUnderscore TO CurrentItem2
    END
    Variables.IncreaseVariable Value: LastUnderscore IncrementValue: 1
    Text.GetSubtext.GetSubtextFromStartTo Text: FileNameNoExtension NumberOfChars: LastUnderscore Subtext=> StartofFileName
    Text.GetSubtext.GetSubtextFrom Text: FileNameNoExtension CharacterPosition: LastUnderscore Subtext=> Subtext
    IF Subtext < 10 THEN
    SET Number TO $'''0%Subtext%'''
    ELSE
    SET Number TO Subtext
    END
    SET NewFileName TO $'''%StartofFileName%%FormattedDateTime%_%Number%'''
    File.RenameFiles.Rename Files: CurrentItem.FullName NewName: NewFileName KeepExtension: True IfFileExists: File.IfExists.Overwrite RenamedFiles=> RenamedFiles
    END

     

    ryule_2-1680018492024.png

     

    ryule_1-1680018390639.png

     

     

  • Pavel_NaNoi Profile Picture
    1,074 on at

    Shouldn't be an issue, as long as the number is in a string format, you'd be able to rename it using the Rename File action as 01,02,03,04, etc.

     

    To get a number that increments like that just do the following:

    -Set variable to 1 and name it something, in this case I'll name it "OriginalNumber" for clarity

    -Put in an IF Statement that asks if %OriginalNumber% is < 10

    If so then:

    -Set variable to 0%OriginalNumber% and name it something, in my case "NumberToWrite"

    -Increase variable %OriginalNumber% by 1 via "Increase Variable" action

    Else:

    -Set Variable %OriginalNumber% to %NumberToWrite%

    -Increase variable %OriginalNumber% by 1

    IF END

    Now just write your number as you'd like.

    Here's an example of what the flow I've written above would look like in PAD:

    Pavel_NaNoi_0-1680020469084.png

     

  • Kaif_Siddique Profile Picture
    2,108 Super User 2024 Season 1 on at

    Here is a sample flow:

     

    Kaif_Siddique_2-1680031357846.png

     

    Copy and Paste

    Folder.GetFiles Folder: $'''D:\\SampleFiles''' FileFilter: $'''*.pdf''' 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 CurrentItem IN Files
     Text.SplitText.SplitWithDelimiter Text: CurrentItem.NameWithoutExtension CustomDelimiter: $'''_''' IsRegEx: False Result=> TextList
     Text.Pad Text: TextList[3] PadPosition: Text.PadPosition.Left PaddingText: 0 TotalLength: 2 PaddedText=> PaddedText
     File.RenameFiles.Rename Files: CurrentItem.FullName NewName: TextList[0] + '_' + TextList[1] + '_' + TextList[2] + '_' + PaddedText KeepExtension: True IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
    END
    

     

    Regards

    Kaif

  • Glueck Profile Picture
    112 on at

    Dear @ryule,  @Pavel_NaNoi,   @Kaif_Siddique

    Thank you very much for your help!!!

    I will try your advice and will provide the feedback😉

     

  • Glueck Profile Picture
    112 on at

    Hi @ryule , since I would like to learn more about PAD, I am trying each advice. For your advice, I tried the same, but got some error. 

    For instance, For #8 "For each", I got the error msg "Positions should be list, database or datarow".

    Before #8, I set each action as below. Please let me know if I am wrong.

     error message.JPGerror message2.JPG

     

  • ryule Profile Picture
    929 Super User 2024 Season 1 on at

    Disable this "First occurrence only" option

     

    ryule_0-1681310543397.png

     

     

     

    Also, this should just be %CurrentItem.FullName%

     

    ryule_1-1681310577422.png

     

  • Glueck Profile Picture
    112 on at

    Hi @ryule , thank you for taking your time to check my error. 

    I amended, but I got the error next for #11. The error msg is "The value should be a number ".

    Is there anything wrong for my setting? Sorry lots of questions...

    error message.JPGerror message4.JPGerror message3.JPGerror message2.JPGerror message1.JPG

  • Verified answer
    momlo Profile Picture
    1,527 Super User 2024 Season 1 on at

    Hi @Glueck / All,

    I scanned the thread and I would suggest simple solution using "PAD Text" action.

    No IFs or any custom logic required:

     

    Folder.GetFiles Folder: $'''C:\\TEST''' 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
    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''ddMMyy''' Result=> date
    SET counter TO 1
    LOOP FOREACH CurrentItem IN Files
     Text.Pad Text: counter PadPosition: Text.PadPosition.Left PaddingText: 0 TotalLength: 2 PaddedText=> number
     File.RenameFiles.Rename Files: CurrentItem NewName: $'''vendorname_%date%_%Number%''' KeepExtension: True IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
     Variables.IncreaseVariable Value: counter IncrementValue: 1
    END
    

     

    momlo_0-1681556650747.png

     

  • Glueck Profile Picture
    112 on at

    @momlo 

    Thank you very much for your advice. Finally this works!!! 

    This is simple and it was helpful😃

    ResultResultJA.JPG

  • Glueck Profile Picture
    112 on at

    Dear @ryule,   @Kaif_Siddique@Pavel_NaNoi 

     

    I tried each advice of yours, unfortunately it was not working(and because of my language issue😣).

    But I really appreciate your kind advice. Thank you very much. 

    Test each adviceTest each advice

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 238 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 225

#3
Haque Profile Picture

Haque 181

Last 30 days Overall leaderboard