mIRC Homepage
Posted By: Bullseye copy and rename - 15/11/06 09:37 PM
I'm looking for a script that copy's a file at the laast day of the month at 23:59
It should rename the file to <monthname_year.htm>
is this possible ?

Greetzz
Posted By: RusselB Re: copy and rename - 15/11/06 11:28 PM
Possible, but not simple, since mIRC doesn't know how many days there are in a month. Since you're wanting to do this just before midnight (by your post 1 minute before) would it make a big difference if the rename happened on the first of the next month just after midnight (ie: possibly 2 minutes later than what you asked for)?
Posted By: Riamus2 Re: copy and rename - 15/11/06 11:37 PM
You can always use $calc and add 1 day to the current date and see if the month changes. That wouldn't be too difficult with a timer and an IF statement for the $calc line.
Posted By: Bob57 Re: copy and rename - 16/11/06 06:40 AM
I’m not sure if it will fit your situation, but when I have a log file that I want to start fresh at midnight, months end, etc I initialize the time of the current period and check that as I send input to the file.
Code:
alias Init.LastSecOfMonth {
  var %ThisMonth = $asctime(m)
  var %ThisYear  = $asctime(yyyy)

  if (%ThisMonth &lt; 12) var %NextMonth = $+($calc(%ThisMonth + 1),/,%ThisYear)
  else                 var %NextMonth = $+(1/,$calc(%ThisYear + 1))

  var %FirstSecNextMonth = $ctime(1/ $+ %NextMonth 0:00)
  set %LastSecOfMonth $calc(%FirstSecNextMonth - 1)

  echo -s   $asctime(%LastSecOfMonth,    y mmm yyyy H:nn)
  echo -s   $asctime(%FirstSecNextMonth, y mmm yyyy H:nn)
}


alias LogInput {
  if ($ctime &gt;= %LastSecOfMonth) {
    var %NewFileName = $asctime(%LastSecOfMonth, mmm_yyyy) $+ .htm
    echo -s   %NewFileName
    ; Do file stuff
    ; re intialize %LastSecOfMonth
  }
  ; do the logging
}  

The code is rough and long, but maybe you can adapt it to fit your situation.
Posted By: DaveC Re: copy and rename - 16/11/06 11:17 AM
alias aliasNAMEHERE {
if (!$1) { .timerNAMEHERE 23:59 1 0 aliasNAMEHERE CHECK | return }
if ($1 == CHECK) {
if ($date($ctime,mm) != $date($calc($ctime + 120),mm)) { copy "filename" $+(",$date(mmmm_yyyy),.htm") }
.timer 1 120 aliasNAMEHERE
}
}

*usage /aliasNAMEHERE
This well trip the timer off to go off at 23:59, with a $1 of "CHECK"
When the timer goes off it checks if current month digits are not equal to the one in 2 mins, and if so copy "filename" to "month_year.htm", lastely either way it sets of a 120 second timer to set of the inital 23:59 timer, you dont want to set that off for 2 mins or so, to ensure that your not tripping it again becuase your still at say 23:59:02, aka delay 120 seconds to 00:01:02 and setup the timer again.

* u might want to consider using a vbs script or a /RUN CMD to do the copy if the file is large, as the internal copy command freezes up mirc for the time it takes to copy the file, if this is insignificant then dont worry about it., also if your going to then erase the file u might consider using /rename instead of /copy
Posted By: Riamus2 Re: copy and rename - 16/11/06 02:32 PM
Here's the command for using /run:

/run -n cmd /c copy filename filename
Posted By: DaveC Re: copy and rename - 16/11/06 06:52 PM
Thanks i didnt know that <snicker snicker> and heres the .vbs scripted up as a command.

Code:
;Usage $copyfile(&lt;source&gt;,&lt;destination&gt;)[.force]
;
; $1 = sourcepath\file       (must exist)
; $2 = destinationpath\file  (must not exist, unless $copyfile().force property invoked)
;
alias copyfile {
  if (($isfile($1)) &amp;&amp; (($prop == force) || (!$isfile($2)))) {
    if ((!$isfile($+($scriptdir,copy.vbs))) || ($file($+($scriptdir,copy.vbs)).size != 196)) {
      write -c $+($scriptdir,copy.vbs) dim filesys
      write    $+($scriptdir,copy.vbs) dim args
      write    $+($scriptdir,copy.vbs) dim src
      write    $+($scriptdir,copy.vbs) dim dst
      write    $+($scriptdir,copy.vbs) set args    = WScript.Arguments
      write    $+($scriptdir,copy.vbs) src         = args.Item(0)
      write    $+($scriptdir,copy.vbs) dst         = args.Item(1)
      write    $+($scriptdir,copy.vbs) set filesys = CreateObject("Scripting.FileSystemObject")
      write    $+($scriptdir,copy.vbs) filesys.CopyFile src, dst
    }
    run $qt($+($scriptdir,copy.vbs)) $qt($1) $qt($2)
  }
}


* be aware who ever uses it, its not valid filename checked, you can do that yourself if u like. *
Posted By: Riamus2 Re: copy and rename - 17/11/06 01:14 AM
Sorry, wasn't meant as a reply to you, but just the info for that person. I assumed you knew since you mentioned it. smile
Posted By: DaveC Re: copy and rename - 17/11/06 01:35 AM
lol yeah i knew u wouldnt have thought i didnt know. Thats why i added the "<snicker>" :-)
© mIRC Discussion Forums