mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2003
Posts: 46
D
DJSi Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2003
Posts: 46
Hi,

I'm trying to write a script to msg a channel (eg. #test) when a file is created in a folder (eg. C:\Test).

So...

1. C:\Test\Readme.txt is created
2. I say "File Readme.txt has been created." in channel #test (obviously automatically).

Something like that. Should be easy, but I can't work it out!

Any help would be appreciated.
Thanks smile

Joined: Dec 2002
Posts: 208
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 208
you want to do this when a file is created by mIRC in a folder .. ir when a file is created by any means in a folder (for example even if you created it manualy in windows, or if anouther program besides mIRC created it) ???

there is no event in mIRC that trigers when a new file is created. so beings there is no event for it, the only way you can know if any new file is created (be it from mIRC or not) in a given folder u would have to manualy monitor the contents of that folder ..

write an alias to check to see if a new file is in the folder .. to do this you would obviously have to know what files were already in that folder, so the first time the alias runs u will need to store in memory somehow the current contents of the folder. . be it by varable, hash table, ini file .. or however .. then u need to compair the current contents with the old .. use $findfile()

have the alias do whatever it is you want it to do when a new file is created.

now that you have an alias to check for a new file, and beings we have no event that automaticly trigers, u will have to have a timer run the alias every so often to check the folder manualy.

timer 0 30 newfile.chk

for example .. asuming the name of your aliases in this case is 'newfile.chk' .. this timer will run the alias once every 30 seconds (which i'd guess would be sufficent)

and your alias would then do whatever it is your wanting to do.

if you need help writeing the specific alias let us know, but that should be fairly simple for you.


if you want something that trigers only when a new file is created by a script .. u could write your own write { } and writeini { } identifers to check to see if the file your trying to write to already exists or not, if not then u know mIRC will creat a new file after execution ..

for example
Code:
write {
  if (!$exists($$1)) { ; it will be a new file, do whatever }
  !write $1 $2-
}


hope this answered your question.

Cobra^

Joined: Jan 2003
Posts: 46
D
DJSi Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2003
Posts: 46
Thanks for the reply. Didn't realise it wasn't possible or certainly not that easy to do. frown

All I'm trying to do is notify a channel when a batch process is complete. The reason I asked about the file creation was cause it would be simple to make my batch file create and file so that this script notified the channel of it.

So, alternatively, is there a way to message a channel from a batch file? All I need it to do is do something like "/msg #test File blah blah is created".

Although, I guess it's difficult to get a batch file to intergrate itself and use Mirc in this way. I have tried a key typer program, to send the keys to Mirc, but this doesn't work either. frown

I guess I could use some type of Eggdrop bot, but this I assume would be even more complicated as I would need to programme it in TCL.

Any ideas?

Thanks again for your help smile

Joined: Dec 2002
Posts: 102
M
Vogon poet
Offline
Vogon poet
M
Joined: Dec 2002
Posts: 102
What's the batch file doing exactly? Most of the commands in a batch file can be reproduced in mIRC directly. You can also use run -n <command> to execute single commands that mIRC cannot do itself. Unless it's a long complicated batch file you may be able to translate it into mIRC code.

One way to get a batch file to get a message to a channel through mIRC is if you had some sort of DDE utility. I'm not aware of any command line DDE utililtes though.


-
MIMP
Joined: Jan 2003
Posts: 46
D
DJSi Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2003
Posts: 46
Yes, it is a long complicated process that downloads a series of files, edits them and re-uploads them. It's a process that my company uses to update a certain section of their website.

I believe I found a DDE type application, but it doesn't work with Mirc (for some reason?), maybe you can shed more light on it?

See here:
http://wwwthep.physik.uni-mainz.de/~frink/nt.html
(about half way down)

You can use it to send "keys" to applications. Works with things like Notepad or Command Prompt, but not Mirc frown

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Quote:
All I'm trying to do is notify a channel when a batch process is complete.

You can call /xrun with the -w (wait) flag, e.g. //xrun -wn file.bat | msg #chan Finished.

Joined: Jan 2003
Posts: 46
D
DJSi Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2003
Posts: 46
Thanks. Do you mean I would use this extension to run the batch file itself? And obviously report back once it's finished?

Unfortunately, because this process is all automatic the running of the batch file has to be too. I run it currently using Scheduled Tasks, because it needs to run at certain particular times.

I guess if there is a way to schedule this in MIrc itself that would be fine then! smile

Thanks for the suggestions smile

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Yes. First, open your remote (Alt+R) and paste this:
  • alias runBatch {
    xrun -wn file.bat
    msg # Finsihed
    }
Now you can use the /timer command to call this alias once in a while. For example:
  • /timerBatch 0 300 runBatch [call it every 5 minutes]
    /timerBatch 0 3600 runBatch [call it every hour]
    /timerBatch 0 86400 runBatch [call it every day]
    /timerBatch 14:00 1 60 runBatch [call it once in 2pm]
The timer can be stopped at any time with /timerBatch off. See /help /timer for more.

Joined: Jan 2003
Posts: 46
D
DJSi Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2003
Posts: 46
Sorry for the delay in replying wink

Thanks for this. This can be a temporary solution I guess. See trouble is that the last part of the batch file is to upload a file to a FTP site, using this method, I will have to guess roughly how long it will take to upload it and then schedule the msg in Mirc accordingly. However, if the upload overruns or the internet is slow or the FTP server is busy or something, then it will msg the channel when it hasn't finished uploading, which may cause quite a problem.

Alternatively, can Mirc echo the contents of a text file? I can easily get the batch file to put the file into the text file, but I guess the problem is still telling Mirc *when* to echo the contents. Hmmm. Any ideas? Unless I just get it to repeat the process over and over every 5 minutes or something, until the file exists?

Thanks for your help smile

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
From your original message it would seem you want to notify the channel whenever any file is create anywhere on some root folder. This would be a serious trouble. But if you are only looking for a specific file name, simply use $isfile(c:\file.txt) to tell whether it exists. And there's no problem to repeat this process every X minutes: /timer 0 300 myCheckingAlias

When you call your batch file, you can redirect the output of ftp.exe to a text file which will be looking like this:
  • ...
    ...
    ftp> put c:\local\file.ext
    200 PORT command successful
    150 Opening ASCII mode data connection for mirc.ini
    226 Transfer complete
    ftp: 8590 bytes sent in 1.10Seconds 7.81Kbytes/sec
    ftp> quit
    221 Goodbye
so that when /xrun finishes and the control returns to mIRC you can tell whether it has succeeded:
  • if $read(c:\file.txt,wn,226*) { msg #chan Successfully updated files. }
    else msg #chan An error occured. Type !debug to get my FTP log
For more info see /help $read

Joined: Jan 2003
Posts: 46
D
DJSi Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2003
Posts: 46
Ok thats good. But I'm a little confused...

Will the $read actually echo the txt file to the channel?

Because the file that is uploaded has a different name each time, I need it to echo it to the channel also.

Also, you know where you put /timer 0 300 myCheckingAlias
"myCheckingAlias" where is this? Is this the name of the script?

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
That $read just confirms your file.txt has a line beginning with "226" and if so, it tells the channel the upload was successful. Do you want to message the channel with every line starting with "ftp> put" so they can see the files it has uploaded?

"myCheckingAlias" is just the name you can give to an alias that will check if a file exists, and this alias will be called by your timer every 5 minuts (300 secs). For example -
  • alias myCheckingAlias {
    if $isfile(c:\file.txt) { msg #chan file exists }
    else msg #chan file doesn't exist
    }

Joined: Jan 2003
Posts: 46
D
DJSi Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2003
Posts: 46
I want to message the channel like this:

DJSi> NEW UPLOAD: File SystemStats-26-03-2004.dat uploaded.

Obviously systemstats.dat being an example file. It doesn't need to show all the FTP commands/transfers etc.

As you can see from that filename, what mainly changes is the date. If we could do something like this:

alias myCheckingAlias {
if $isfile(c:\systemstats-%day%-%month%-%year%.dat) { msg #chan file %found% exists }
else msg #chan file doesn't exist
}

I realise thats not the proper syntax, the bits in % % being variables and %found% being the file found: "SystemStats-26-03-2004.dat" If it could do something like that it would be perfect! grin

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
This alias is looking for a file with today's date:

alias myCheckingAlias {
var %file = c:\systemstats- $+ $asctime(dd-mm-yyyy) $+ .dat
if $isfile(%file) { msg #chan file %file exists }
else msg #chan file doesn't exist
}

Joined: Jan 2003
Posts: 46
D
DJSi Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2003
Posts: 46
Nice smile I'll test it out and let you know how it goes

Thanks!

Joined: Jan 2003
Posts: 46
D
DJSi Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2003
Posts: 46
Worked wonderfully smile Thanks wink

I just need to jaz it up a bit and get it looking good.

I have tried this, cause I don't want it displaying the path to the file also, but it always says that the file doesn't exist !?!

alias releases {
var %file = Systemstats- $+ $asctime(dd-mm-yyyy) $+ .dat
if $isfile("D:\Notify\%file") { msg #blah File uploaded - %file }
else msg #blah no file uploaded.
}

Also how could I add colour & bold to the "File uploaded" text so that it stands out?

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Try this:
  • alias releases {
    var %file = D:\Notify\Systemstats- $+ $asctime(dd-mm-yyyy) $+ .dat
    if $isfile(%file) { msg #blah File uploaded - $nopath(%file) }
    else msg #blah no file uploaded.
    }
(the unknown 'box' is the Ctrl+B bold code. See /help control codes for more)

Joined: Jan 2003
Posts: 46
D
DJSi Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2003
Posts: 46
I can't seem to get this working. Everytime it says that there is no file uploaded. I've tried putting double quotes round the path, but it still doesn't work.

Any ideas? confused

Thanks wink


Link Copied to Clipboard