Computing Staff
  • 0

Batch Rename – Epoch Time To Human Time

  • 0

hi, I have a bunch of htm files (B1-60164.htm, B1-60165.htm, etc.) with runs a javascript to convert epoch time to normal human time.

i managed to determine the script call (not the actual js):

<SCRIPT language=”JavaScript”>document.write(format_date(1364400000));</SCRIPT>

my intention is to extract the epoch time 1364400000 and convert it into yymm date format, and append to the filename (1303_B1-60164.htm, 1303_B1-60165.htm, etc.)

fyi: epoch time 1364400000 is 18 March 2013, GTM+8.

in short, extract the epoch time within htm files, convert to human time, and append yymm (year+month) to the filename.

this is via Windows batch script/command.

thanks!

Share

1 Answer

  1. Yeh, at one point it occured to me it might be something to do with date format, but the line# (that got the error) threw me off the scent. (Seriously! I’m not just covering!)
    At any rate, vbscript has functions that might handle this, and also M2’s approach, but that requires debug, and 64-bit machines don’t support debug. Try this snippet/test on your system and see if it gets it right:
    ‘==== begin vbscript datest
    z=date
    call test()
    wscript.echo “enter a test date: ”
    z=wscript.stdin.readline
    call test()
    sub test()
    wscript.echo z
    e=formatdatetime(z)
    wscript.echo e
    d=datepart(“d”,z)
    m=datepart(“m”,z)
    y=datepart(“yyyy”,z)
    wscript.echo “year:”,y,” “,right(“20″&y;,2)
    wscript.echo “month: “,m,” “,right(“0″&m;,2)
    wscript.echo “day: “,right(“0″&d;,2)
    ‘==== end vbscript
    Here’s my last posted vbscript amended to implement this. Hopefully it can handle regional settings since it accesses the system to get the settings:

    ‘===== begin vbscript “ep.vbs”
    set regx=new regexp
    regx.global=true
    ‘======== date decipher
    regx.pattern=”[^0-9]”
    ‘– get the delimiter
    dlm=regx.execute(date)(0)
    ‘– determine position of year element (leading or trailing)
    ye=datepart(“yyyy”,date)
    x=dateadd(“yyyy”,1,date)
    k=split(x,dlm)
    for i=0 to 2
    if k(i)-ye=1 then exit for
    next
    ‘– month and day position don’t matter since they’re both “1”
    base=”1″&dlm;&”1″
    if i=2 then base=base&dlm;&”1970″ else base=”1970″&dlm;&base;
    ‘—— end date-decipher, begin main body
    set fso=createobject(“scripting.filesystemobject”)
    infile=wscript.arguments(0)
    z=fso.opentextfile(infile,1).readall
    ‘this is to skip html files with no 10-digs
    on error resume next
    regx.pattern=”[^0-9][0-9]{10,10}[^0-9]”
    zz=mid(regx.execute(z)(0),2,10)/86400
    x=err.number
    err.clear
    if x=0 then
    nn=dateadd(“d”,zz,base)
    yy=right(“20″&datepart;(“yyyy”,nn),2)
    mm=right(“0″&datepart;(“m”,nn),2)
    a=yy&mm;
    wscript.echo “fso.movefile “+infile+”,”+wscript.arguments(2)+a+”_”+wscript.arguments(1)
    c=wscript.stdin.readline ‘testing
    if c=”r” then ‘testing
    fso.movefile infile,wscript.arguments(2)+a+”_”+wscript.arguments(1)
    end if ‘testing
    end if
    ‘===== end vbscript
    this one stops before each actual rename, and you can choose to skip (for testing), or execute the rename by entering “r”. Just hit ctrl-C to stop the run at any point. For production purposes, just remove the three lines around the movefile function.

    • 0