mIRC Home    About    Download    Register    News    Help

Print Thread
#164762 15/11/06 09:37 PM
Joined: Feb 2005
Posts: 344
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
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

#164763 15/11/06 11:28 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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)?

#164764 15/11/06 11:37 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
#164765 16/11/06 06:40 AM
Joined: Dec 2004
Posts: 66
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2004
Posts: 66
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.

#164766 16/11/06 11:17 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
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

#164767 16/11/06 02:32 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Here's the command for using /run:

/run -n cmd /c copy filename filename


Invision Support
#Invision on irc.irchighway.net
#164768 16/11/06 06:52 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
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. *

#164769 17/11/06 01:14 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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


Invision Support
#Invision on irc.irchighway.net
#164770 17/11/06 01:35 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
lol yeah i knew u wouldnt have thought i didnt know. Thats why i added the "<snicker>" :-)


Link Copied to Clipboard