How to Detect a new file added to a folder and copy to the local machine
How to Detect a new file added to a folder and copy to the local machine
am 05.10.2007 12:11:53 von Andy
There is a remote windows server and there is a folder named dir in
that.
Daily basis a new file is added to that perticular folder "dir". lets
say the files added will be of type abc.txt,acd.txt etc.
I want to write a perl script that will detect that new file as soon
as added to "dir" and copy to my local machine.
After that I will do some operation onto that file.
Running that script continuously can be done by using task scheduler
in windows but how can we detect the new file added to that "dir"
folder.
Re: How to Detect a new file added to a folder and copy to the local machine
am 05.10.2007 12:25:31 von QoS
andy wrote in message-id: <1191579113.255421.77760@19g2000hsx.googlegroups.com>
>
> There is a remote windows server and there is a folder named dir in
> that.
> Daily basis a new file is added to that perticular folder "dir". lets
> say the files added will be of type abc.txt,acd.txt etc.
>
> I want to write a perl script that will detect that new file as soon
> as added to "dir" and copy to my local machine.
> After that I will do some operation onto that file.
>
> Running that script continuously can be done by using task scheduler
> in windows but how can we detect the new file added to that "dir"
> folder.
if (-e $file) {
#the file has been detected
}
Re: How to Detect a new file added to a folder and copy to the local machine
am 05.10.2007 16:36:51 von Ben Morrow
Quoth andy :
> There is a remote windows server and there is a folder named dir in
> that.
> Daily basis a new file is added to that perticular folder "dir". lets
> say the files added will be of type abc.txt,acd.txt etc.
>
> I want to write a perl script that will detect that new file as soon
> as added to "dir" and copy to my local machine.
> After that I will do some operation onto that file.
>
> Running that script continuously can be done by using task scheduler
> in windows but how can we detect the new file added to that "dir"
> folder.
Either keep a list of the files you saw last time and compare to the
list of files you have now:
perldoc -f opendir
perldoc -f readdir
or, since you're on Windows, you can retrieve the creation time of a
file from the ctime member of the stat structure:
perldoc -f stat
perldoc File::stat
and check if it's new.
Ben
Re: How to Detect a new file added to a folder and copy to the localmachine
am 05.10.2007 17:16:00 von veatchla
andy wrote:
> There is a remote windows server and there is a folder named dir in
> that.
> Daily basis a new file is added to that perticular folder "dir". lets
> say the files added will be of type abc.txt,acd.txt etc.
>
> I want to write a perl script that will detect that new file as soon
> as added to "dir" and copy to my local machine.
> After that I will do some operation onto that file.
>
> Running that script continuously can be done by using task scheduler
> in windows but how can we detect the new file added to that "dir"
> folder.
>
I am not sure this will work for you since you are working with a remote
server.
I keep a text file in the directory I am monitoring. This file contains
the date/time of the newest files update time stamp. I then loop
through all files in the directory and skip processing all files which
have a update time stamp, using stat(), earlier than the date/time I
saved in the text file. The date/time stamp text file is then updated
with the newest update time stamp, using stat().
--
Len