+ Post New Thread
Results 1 to 13 of 13
Scripts Thread, Script to copy file and rename with YYMMDD_HHMM in Coding and Web Development; How can I do this??? I need to copy an image and rename it to YYYYMMDD_HHMM.jpg Cheers James...
  1. #1
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    720
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40

    Question Script to copy file and rename with YYMMDD_HHMM

    How can I do this???

    I need to copy an image and rename it to YYYYMMDD_HHMM.jpg

    Cheers

    James

  2. #2

    sonofsanta's Avatar
    Join Date
    Dec 2009
    Location
    Lincolnshire, UK
    Posts
    4,988
    Thank Post
    864
    Thanked 1,451 Times in 998 Posts
    Blog Entries
    47
    Rep Power
    618
    Random point while I skive off digging through the T&Cs of a contract: have you looked at IrfanView's batch function? It can do batch renaming, could well be worth a punt.

  3. #3

    SpuffMonkey's Avatar
    Join Date
    Jul 2005
    Posts
    2,240
    Thank Post
    55
    Thanked 278 Times in 186 Posts
    Rep Power
    134
    Heres a similar situation in a batch file I use to save some daily log files - hope its of some help


    for /F "tokens=1,2" %%d in ('date /T') do set day=%%d & set date=%%e
    set yyyy=%DATE:~6,4%
    set mm=%DATE:~3,2%
    set dd=%DATE:~0,2%
    set dateserial=%yyyy%%mm%%dd%
    ren filedel.log %dateserial%_filedel.log

  4. Thanks to SpuffMonkey from:

    Admiral208 (16th November 2010)

  5. #4
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    720
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40
    I need it as a script that can run as a scheduled task... probably should have mentioned that.

  6. #5
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    720
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40
    Quote Originally Posted by SpuffMonkey View Post
    Heres a similar situation in a batch file I use to save some daily log files - hope its of some help


    for /F "tokens=1,2" %%d in ('date /T') do set day=%%d & set date=%%e
    set yyyy=%DATE:~6,4%
    set mm=%DATE:~3,2%
    set dd=%DATE:~0,2%
    set dateserial=%yyyy%%mm%%dd%
    ren filedel.log %dateserial%_filedel.log
    That's brilliant. Ive been searching for ages. How can I add the time as HHMM after the date?

  7. #6
    themightymrp's Avatar
    Join Date
    Dec 2009
    Location
    Leeds, West Yorkshire
    Posts
    1,217
    Thank Post
    215
    Thanked 226 Times in 195 Posts
    Rep Power
    73
    With a slight modification to the above script you get:

    @echo off
    for /F "tokens=1,2" %%d in ('date /T') do set day=%%d & set date=%%e
    set yyyy=%DATE:~6,4%
    set mm=%DATE:~3,2%
    set dd=%DATE:~0,2%
    set dateserial=%yyyy%%mm%%dd%
    set hh=%time:~0,2%
    set mi=%time:~3,2%
    set timeserial=%hh%%mi%
    ren filedel.log %dateserial%_%timeserial%.log

  8. Thanks to themightymrp from:

    Admiral208 (16th November 2010)

  9. #7
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    720
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40
    Brilliant!!!! Just what I needed!

    Thanks All

  10. #8
    somabc's Avatar
    Join Date
    Oct 2007
    Location
    London
    Posts
    2,337
    Thank Post
    83
    Thanked 388 Times in 258 Posts
    Rep Power
    111
    Yes you can use the inbuilt functions 'Time' and 'Date' and pick out the parts you need.

  11. #9
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    720
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40
    Is there a way to ensure that there is a leading zero in the time part??

    When I ran the script this morning, at 8.57am, the file output was 20101117_ 857.jpg, is there a way of displaying 20101117_0857.jpg??

    is quite important because the next time the script runs is 10am. this means that the 10am images appears before the 8.57am image because of the filename.

    Thanks

  12. #10
    themightymrp's Avatar
    Join Date
    Dec 2009
    Location
    Leeds, West Yorkshire
    Posts
    1,217
    Thank Post
    215
    Thanked 226 Times in 195 Posts
    Rep Power
    73
    Change the code slightly to be like this:

    @echo off
    for /F "tokens=1,2" %%d in ('date /T') do set day=%%d & set date=%%e
    set yyyy=%DATE:~6,4%
    set mm=%DATE:~3,2%
    set dd=%DATE:~0,2%
    set dateserial=%yyyy%%mm%%dd%
    set hours=%time: =0%
    set hh=%hours:~0,2%
    set mi=%time:~3,2%
    set timeserial=%hh%%mi%
    ren whatever.jpg %dateserial%_%timeserial%.jpg

    That should do it

  13. Thanks to themightymrp from:

    Admiral208 (17th November 2010)

  14. #11
    Admiral208's Avatar
    Join Date
    Mar 2008
    Location
    Bridgwater
    Posts
    720
    Thank Post
    176
    Thanked 63 Times in 55 Posts
    Rep Power
    40
    Thank you. My only problem now is that I wont be able to test until tomorrow morning. Im sure it will be fine though.

    Thanks again

  15. #12
    neodong's Avatar
    Join Date
    Dec 2010
    Posts
    7
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    i am usually create it with visual basic 6 if the problem using windows operating system

  16. #13


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,999
    Thank Post
    230
    Thanked 2,689 Times in 1,985 Posts
    Rep Power
    789
    Quote Originally Posted by Admiral208 View Post
    When I ran the script this morning, at 8.57am, the file output was 20101117_ 857.jpg, is there a way of displaying 20101117_0857.jpg
    If your images are from a digital camera or webcam you could use ExifTool to read the time and date directly from the image itself.

    Code:
    FOR %%i IN (*.jpg) DO EXIFTOOL -d "%%Y%%m%%d_%%H%%M%%S.jpg" "-FileName<DateTimeOriginal" "%%i"

SHARE:
+ Post New Thread

Similar Threads

  1. Script to copy file if accessed today
    By THERADIOTUBBY in forum Coding
    Replies: 3
    Last Post: 19th September 2010, 06:04 PM
  2. File copy script
    By Quackers in forum Scripts
    Replies: 2
    Last Post: 21st August 2010, 10:20 AM
  3. File Rename Script
    By Jackd in forum How do you do....it?
    Replies: 2
    Last Post: 19th November 2008, 07:39 AM
  4. Rename and Copy local file to Server
    By mrforgetful in forum How do you do....it?
    Replies: 4
    Last Post: 26th February 2008, 02:56 PM
  5. Replies: 4
    Last Post: 23rd March 2006, 06:27 AM

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
  •