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 / Running into an issue ...
Power Automate
Suggested Answer

Running into an issue with coding a task . . . . hopefully, you can get me started

(0) ShareShare
ReportReport
Posted on by 22
I need to copy a Zip file(s) that have not been previously copied to a backup folder and then in that back up folder I only want to keep anything older than say 10 days from the current date.
 
I have tried having copilot right it or at least get me started but it is not understanding what I say or what, but it is not doing it . . . 
 
I have tried to use what I already know (which is not much) but I cannot figure it out.  The issue is File names trying to convert to Date is B241017B.zip, B241016B.zip, B241015B.zip, B241015C.zip, B241015D.zip were the letter after the 6 digit date after the letter B could be any letter as you can see.
 
This is what I have now and it assumes that the file name has the letter B as the Seperator.  Please help me figure out how to account for the different letter at the end of the name.
 
 
SET SourceFolder TO $'''E:\\AMES'''
SET DestinationFolder TO $'''E:\\Operations\\AMES'''
Folder.GetFiles Folder: SourceFolder FileFilter: $'''B*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> SourceFiles
Folder.GetFiles Folder: DestinationFolder FileFilter: $'''B*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> DestinationFiles
DateTime.GetCurrentDateTime.Windows DateTimeFormat: DateTime.DateTimeFormat.DateOnly TimeZoneLocation: DateTime.TimeZoneLocation.EasternStandardTime CurrentDateTime=> CurrentDateTime
LOOP FOREACH SourceFile IN SourceFiles
    SET SourceFileName TO SourceFile.NameWithoutExtension
    Text.SplitText.SplitWithDelimiter Text: SourceFileName CustomDelimiter: $'''B''' IsRegEx: False Result=> SourceTextList
    Text.ConvertTextToDateTime.ToDateTimeCustomFormat Text: SourceTextList[1] CustomFormat: $'''yyMMdd''' DateTime=> SourceTextAsDateTime
    DateTime.Subtract FromDate: CurrentDateTime SubstractDate: SourceTextAsDateTime TimeUnit: DateTime.DifferenceTimeUnit.Days TimeDifference=> TimeDifference
    IF TimeDifference < 10 THEN
        File.Move Files: SourceFile Destination: DestinationFolder IfFileExists: File.IfExists.DoNothing MovedFiles=> MovedFiles
    END
END
LOOP FOREACH DestinationFile IN DestinationFiles
    SET DestinationFileName TO DestinationFile.NameWithoutExtension
    Text.SplitText.SplitWithDelimiter Text: DestinationFileName CustomDelimiter: $'''B''' IsRegEx: False Result=> DestinationTextList
    Text.ConvertTextToDateTime.ToDateTimeCustomFormat Text: DestinationTextList[1] CustomFormat: $'''yyMMdd''' DateTime=> DestinationTextAsDateTime
    DateTime.Subtract FromDate: CurrentDateTime SubstractDate: DestinationTextAsDateTime TimeUnit: DateTime.DifferenceTimeUnit.Days TimeDifference=> DestinationTimeDifference
    IF DestinationTimeDifference > 10 THEN
        File.Delete Files: DestinationFile
    END
END
 
I have the same question (0)
  • Suggested answer
    Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at
    Hi,
     
    Try this updated code
     
    SET SourceFolder TO $'''D:\\Temp\\Test'''
    SET DestinationFolder TO $'''D:\\Temp\\TestOutput'''
    Folder.GetFiles Folder: SourceFolder FileFilter: $'''B*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> SourceFiles
    Folder.GetFiles Folder: DestinationFolder FileFilter: $'''B*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> DestinationFiles
    DateTime.GetCurrentDateTime.Windows DateTimeFormat: DateTime.DateTimeFormat.DateOnly TimeZoneLocation: DateTime.TimeZoneLocation.EasternStandardTime CurrentDateTime=> CurrentDateTime
    LOOP FOREACH SourceFile IN SourceFiles
        SET SourceFileName TO SourceFile.NameWithoutExtension
        Text.ParseText.RegexParseForFirstOccurrence Text: SourceFileName TextToFind: $'''(?<=B)\\d{6}''' StartingPosition: 0 IgnoreCase: False Match=> SourceDate
        Text.ConvertTextToDateTime.ToDateTimeCustomFormat Text: SourceDate CustomFormat: $'''yyMMdd''' DateTime=> SourceTextAsDateTime
        DateTime.Subtract FromDate: CurrentDateTime SubstractDate: SourceTextAsDateTime TimeUnit: DateTime.DifferenceTimeUnit.Days TimeDifference=> TimeDifference
        IF TimeDifference < 10 THEN
            File.Move Files: SourceFile Destination: DestinationFolder IfFileExists: File.IfExists.DoNothing MovedFiles=> MovedFiles
        END
    END
    LOOP FOREACH DestinationFile IN DestinationFiles
        SET DestinationFileName TO DestinationFile.NameWithoutExtension
        Text.ParseText.RegexParseForFirstOccurrence Text: DestinationFileName TextToFind: $'''(?<=B)\\d{6}''' StartingPosition: 0 IgnoreCase: False Match=> DestinationDate
        Text.ConvertTextToDateTime.ToDateTimeCustomFormat Text: DestinationDate CustomFormat: $'''yyMMdd''' DateTime=> DestinationTextAsDateTime
        DateTime.Subtract FromDate: CurrentDateTime SubstractDate: DestinationTextAsDateTime TimeUnit: DateTime.DifferenceTimeUnit.Days TimeDifference=> DestinationTimeDifference
        IF DestinationTimeDifference > 10 THEN
            File.Delete Files: DestinationFile
        END
    END
    
     
    Here i have updated the code to handle the extraction of dates 
     
    See whether this helps !
     
    Mark it as solution if it resolves your query !
     
    Thanks & Regards,
    Nived N

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 274 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 175

#3
Haque Profile Picture

Haque 166

Last 30 days Overall leaderboard