locked
Rename Files' Name In Batch RRS feed

  • Question

  • User546194788 posted

    There are about 300 files which file's name format is like below.

    20200908-1001.jpg
    20200908-1002.jpg
    ...
    20200908-1300.jpg

    How to code a batch script to rename file's name as below?

    1001.jpg
    1002.jpg
    ...
    1300.jpg

    Tuesday, September 8, 2020 8:14 PM

Answers

  • User1535942433 posted

    Hi aspfun,

    Do you have solve your problems?If you have solved,you could mark these helpful answers.If you still have problems,you could post new thread to us.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2020 3:10 AM

All replies

  • User409696431 posted

    What framework and language are you using? And which part do you not know how to do?

    List the files and iterate through them?

    Get the name and parse what the new name should be?

    Rename the file?

    Run the code on a schedule?

    Tuesday, September 8, 2020 10:27 PM
  • User1535942433 posted

    Hi aspfun,

    Accroding to your description,could you tell us what is your project?

    Accroding to your previous threads,I'm guessing that you have vb codes.You could find the "-" index and remove the substring before "-".

    I have create a demo in vb c#.Just like this:

    Dim items As List(Of String) = New List(Of String)() From {
            "20200908-1001.jpg",
            "20200908-1002.jpg",
            "20200908-1300.jpg"
        }
        Dim filename = New List(Of String)()
    
        For i As Integer = 0 To items.Count - 1
            Dim x = items(i).IndexOf("-", 0)
    
            If x >= 0 Then
                Dim y = items(i).Substring(0, x + 1)
                Dim k = items(i).Remove(0, y.Count())
                filename.Add(k)
            End If
        Next

    If you have problems,you could tell us more details of your projects or post your current codes to us.It will help us to solve your problems.

    Best regards,

    Yijing Sun

    Wednesday, September 9, 2020 6:05 AM
  • User546194788 posted

    Thank you. I learn the logic.

    Wednesday, September 9, 2020 12:28 PM
  • User1535942433 posted

    Hi aspfun,

    Do you have solve your problems?If you have solved,you could mark these helpful answers.If you still have problems,you could post new thread to us.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2020 3:10 AM