Results 1 to 6 of 6

Thread: Rename files based on creation date / time

  1. #1
    Chaos Monkey Apex's Avatar
    Join Date
    Jul 2003
    Location
    Huddersfield
    Posts
    4,706
    Thanks
    1,139
    Thanked
    284 times in 203 posts
    • Apex's system
      • Motherboard:
      • Asus Z87M-PLUS
      • CPU:
      • Intel i5-4670K
      • Memory:
      • 32 GiB
      • Storage:
      • 20 TiB
      • Graphics card(s):
      • PowerColor Radeon RX 6700 Fighter 10GB OC
      • PSU:
      • 750
      • Case:
      • Core View 21
      • Operating System:
      • Windows 10 pro
      • Monitor(s):
      • Dell S2721DGFA
      • Internet:
      • 200Mb nTL Cable

    Question Rename files based on creation date / time



    Am trying to figure out if it is possible to batch script the renaming of a bunch of files based on their creation date / time

    eg

    c:\temp\

    file.tmp
    file(1).tmp
    file(2).tmp
    file(3).tmp
    file(4).tmp

    rename them to

    file_01_01_2013.tmp
    file_02_01_2013.tmp
    file_03_01_2013.tmp
    file_04_01_2013.tmp
    file_05_01_2013.tmp

    and if needs be stick the time stamp in there too

    The issue we have is the current rename batch script runs once a week on a Friday to copy the files to a remote system / share but it can not handle it if the file name used is already the remote location; because the rename function in the script just seems to be renaming all the sources files with that days date [the date the batch script ran] - so in effect it isn't doing what it should be

    any ideas ?
    Last edited by Apex; 20-09-2013 at 03:05 AM.

  2. #2
    root Member DanceswithUnix's Avatar
    Join Date
    Jan 2006
    Location
    In the middle of a core dump
    Posts
    12,986
    Thanks
    781
    Thanked
    1,588 times in 1,343 posts
    • DanceswithUnix's system
      • Motherboard:
      • Asus X470-PRO
      • CPU:
      • 5900X
      • Memory:
      • 32GB 3200MHz ECC
      • Storage:
      • 2TB Linux, 2TB Games (Win 10)
      • Graphics card(s):
      • Asus Strix RX Vega 56
      • PSU:
      • 650W Corsair TX
      • Case:
      • Antec 300
      • Operating System:
      • Fedora 39 + Win 10 Pro 64 (yuk)
      • Monitor(s):
      • Benq XL2730Z 1440p + Iiyama 27" 1440p
      • Internet:
      • Zen 900Mb/900Mb (CityFibre FttP)

    Re: Rename files based on creation date / time

    Can you install software on the machine that needs to do this?

    Life is too short to waste on trying to get batch scripts to work. Python, Ruby or Bash would be the usual things to try. They are a useful skill to have too, also very nice on a CV

  3. #3
    Senior Member
    Join Date
    May 2013
    Posts
    215
    Thanks
    3
    Thanked
    21 times in 19 posts
    • bytejunkie's system
      • Motherboard:
      • ASRock P5S Pro
      • CPU:
      • i5 750
      • Memory:
      • 8GB Patriot IEM
      • Storage:
      • Samsung 840Pro 128GB
      • Graphics card(s):
      • XFX 6870
      • PSU:
      • Powercooler 600
      • Case:
      • Thermal Take Dokker
      • Operating System:
      • Win7
      • Monitor(s):
      • Apple Cinema Screen
      • Internet:
      • yup

    Re: Rename files based on creation date / time

    show me the line that renames it to the date the batch file ran and i'll show you a line that renames it to date it was created if its feasible.

    you dont say what language its in, so make sure you tell us that.

  4. #4
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: Rename files based on creation date / time

    powershell would make this easier? Is that an option?
    throw new ArgumentException (String, String, Exception)

  5. #5
    Chaos Monkey Apex's Avatar
    Join Date
    Jul 2003
    Location
    Huddersfield
    Posts
    4,706
    Thanks
    1,139
    Thanked
    284 times in 203 posts
    • Apex's system
      • Motherboard:
      • Asus Z87M-PLUS
      • CPU:
      • Intel i5-4670K
      • Memory:
      • 32 GiB
      • Storage:
      • 20 TiB
      • Graphics card(s):
      • PowerColor Radeon RX 6700 Fighter 10GB OC
      • PSU:
      • 750
      • Case:
      • Core View 21
      • Operating System:
      • Windows 10 pro
      • Monitor(s):
      • Dell S2721DGFA
      • Internet:
      • 200Mb nTL Cable

    Re: Rename files based on creation date / time

    Code:
    Set DD=%DATE:~0,2%
    Set MM=%DATE:~3,2%
    Set YYYY=%DATE:~6,4%
    Set DDMMYYY=%DD%%MM%%YYYY%
    
    #Rename d:\leeds_backup\leeds_full.nbf leeds_full_%DD%-%MM%-%YYYY%.nbf - not used anymore but left in the wscript
    Rename d:\leeds_backup\leeds_diff(*).nbf leeds_diff_%DD%-%MM%-%YYYY%.nbf
    Copy D:\Leeds_Backup\leeds_diff_*.nbf \\remote server\ITDept\Leeds_NTI_Backup\
    Move D:\Leeds_Backup\leeds_diff_*.nbf D:\copied_backup\
    d:\postie\postie -host:<mailserver> -to:<emailadderss> -from:<remote server> -s:"description/subject" -nomsg
    Business info removed

    Nothing new can be installed on this; the business users will not allow it currently.

    There is a i think a plan in place to replace the current setup but till then we have to make the best use of the tools we have

  6. #6
    Registered User
    Join Date
    Aug 2015
    Posts
    1
    Thanks
    0
    Thanked
    0 times in 0 posts

    Re: Rename files based on creation date / time

    Quote Originally Posted by TheAnimus View Post
    powershell would make this easier? Is that an option?
    yes we can use it however a BatchRenameFiles Tool could also be an option. Regards, Fedya

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •