Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch renaming files  (Read 9712 times)

0 Members and 1 Guest are viewing this topic.

zooropean

    Topic Starter


    Newbie

    • Experience: Expert
    • OS: Windows 8
    Batch renaming files
    « on: December 10, 2017, 07:22:45 AM »
    Hello,

    I have created 365 excel files, one for each day of 2018. I want to rename them in such a way that the date of each day of the year is part of the filename. For example:

    Some_file 01-01-2018
    Some_file 01-02-2018
    Some_file 01-03-2018
    .
    .
    .
    .
    Some_file 12-31-2018

    I guess I'm looking for a script to accomplish that. I have two renaming programs that accept scripts, but I could also use the command line. Thanks for any help.

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Batch renaming files
    « Reply #1 on: December 10, 2017, 09:38:13 AM »
    If the contents of the files are the same until edited in 2018, then a script with incremental counters could be used to make a copy of one master file and save it as the some_file 01-01-2018 then increments to 2 for the day, logic would be needed to reset the day counter to 1 when the 31rst day of January 2018 is reached and increment month to 2 and then continue then as 02-01-2018 to which it resets the day counter again for each month as the days in the month are different month to month and so. You would need 12 rules to govern what the counter will increment to for each month before resetting back to 1 and incrementing month to next month, then end at December 31, 2018

    I know how to do this in other languages using system calls to interact with command shell to copy and rename the copied file and go to the next, but not sure if batch alone can do this.

    If the contents of each file are different then my above suggestion wouldnt work, but if date is within the file itself it could be read in on a line and then used to rename itself by making a copy with the date appended to the name, and then deletion of the original file that it came from since you cant rename a file that is in use.

    Salmon Trout

    • Guest
    Re: Batch renaming files
    « Reply #2 on: December 10, 2017, 02:12:19 PM »
    Off the top of my head, in VBScript you can just start with a date, 01/01/2018, and add 1 day to it 364 times, using the DateAdd function, listing out the date string for each, or performing the rename, etc. I am going to bed now but if this is still unanswered when I come back from work tomorrow, I'll give it a try.

    Salmon Trout

    • Guest
    Re: Batch renaming files
    « Reply #3 on: December 10, 2017, 03:39:56 PM »
    ...

    Salmon Trout

    • Guest
    Re: Batch renaming files
    « Reply #4 on: December 11, 2017, 12:34:19 PM »
    Without knowing anything about what the 365 files are, and how any renaming scheme is hoped for (what file gets renamed to what?) it is not really possible to offer any script ideas.

    patio

    • Moderator


    • Genius
    • Maud' Dib
    • Thanked: 1769
      • Yes
    • Experience: Beginner
    • OS: Windows 7
    Re: Batch renaming files
    « Reply #5 on: December 11, 2017, 01:49:00 PM »
    + 1 ...
    " Anyone who goes to a psychiatrist should have his head examined. "

    Salmon Trout

    • Guest
    Re: Batch renaming files
    « Reply #6 on: December 11, 2017, 02:09:42 PM »
    it is not really possible to offer any script ideas.
    Never stopped me before:

    Myscript.vbs

    ds   = wscript.arguments(0)
    dj   = wscript.arguments(1)
    nd   = DateAdd("d", dj, ds)
    mm   = month(nd)
    dd   = day  (nd)
    yyyy = year (nd)
    if mm < 10 then mm = "0" & mm : end if
    if dd < 10 then dd = "0" & dd : end if
    nd2 = mm & "-" & dd & "-" & yyyy
    dn = WeekdayName(Weekday(nd),true)
    wscript.echo nd2 & " " & dn


    In the last line, omit everything after wscript.echo nd2 if you don't want the short day name appended.

    Run it with cscript.exe //nologo and feed it 2 quoted parameters: the start date in the format shown, and the number of days forward you want a date to be generated.

    C:\>cscript //nologo myscript.vbs "01-Jan-2018" "6"
    01-07-2018 Sun

    C:\>for /l %N in (0,1,30) do @cscript //nologo myscript.vbs "01-Jan-2018" "%N"
    01-01-2018 Mon
    01-02-2018 Tue
    01-03-2018 Wed
    01-04-2018 Thu
    01-05-2018 Fri
    01-06-2018 Sat
    01-07-2018 Sun
    01-08-2018 Mon
    01-09-2018 Tue
    01-10-2018 Wed
    01-11-2018 Thu
    01-12-2018 Fri
    01-13-2018 Sat
    01-14-2018 Sun
    01-15-2018 Mon
    01-16-2018 Tue
    01-17-2018 Wed
    01-18-2018 Thu
    01-19-2018 Fri
    01-20-2018 Sat
    01-21-2018 Sun
    01-22-2018 Mon
    01-23-2018 Tue
    01-24-2018 Wed
    01-25-2018 Thu
    01-26-2018 Fri
    01-27-2018 Sat
    01-28-2018 Sun
    01-29-2018 Mon
    01-30-2018 Tue
    01-31-2018 Wed