How to rename multiple files?

i have multiple files in our folder i need to rename all files i attached file image.
before.

after i need this format


kindly share workflow…

@domsmgtmeet22,

Use this code in Invoke Code activity.

Dim folderPath As String = "C:\Your folder path"
Dim datePattern As String = "\d{4}-\d{2}-\d{2}"

' Get the list of files and rename them using LINQ
Directory.GetFiles(folderPath, "*.xlsx").
    Select(Function(file) New FileInfo(file)).
    Where(Function(f) System.Text.RegularExpressions.Regex.IsMatch(f.Name, datePattern)).
    ToList().
    ForEach(Sub(f)
        Dim match As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(f.Name, datePattern)
        If match.Success Then
            ' Extract prefix (before date) and the date part
            Dim prefix As String = String.Join("_", f.Name.Split("_"c).TakeWhile(Function(part) Not System.Text.RegularExpressions.Regex.IsMatch(part, datePattern)))
            Dim datePart As String = match.Value
            ' Construct new filename
            Dim newFileName As String = Path.Combine(f.DirectoryName, $"{prefix}_{datePart}.xlsx")
            ' Rename the file
            File.Move(f.FullName, newFileName)
        End If
    End Sub)

Remember to import System.Text.RegularExpressions in your xaml before you run.

Hi @domsmgtmeet22

You can use the following sequence to get this done.

Rename_Test.zip (13.8 KB)

Hope this helps :slight_smile:

Hi @domsmgtmeet22 ,
Isn’t the value after yyyy-MM-dd in the file name DateTime? If the format is the same, you can clean up to the last format character in all files, depending on how many characters there are in the format.

New Name → Left(Path.GetFileNameWithoutExtension(FilePath),Path.GetFileNameWithoutExtension(FilePath).Length-your DateTime format lenght).Trim

share your example workflow

Sure :slight_smile:
RenameMultipleFiles.xaml (8.2 KB)