Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to Detect a new file added to a folder and copy to the local machine

Reply
Thread Tools

How to Detect a new file added to a folder and copy to the local machine

 
 
andy
Guest
Posts: n/a
 
      10-05-2007
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.

 
Reply With Quote
 
 
 
 
QoS@domain.invalid
Guest
Posts: n/a
 
      10-05-2007

andy <(E-Mail Removed)> wrote in message-id: <(E-Mail Removed) om>

>
> 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
}

 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      10-05-2007

Quoth andy <(E-Mail Removed)>:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to copy a file from one machine to another machine Nico Grubert Python 1 09-21-2005 10:53 AM
Re: How to copy a file from one machine to another machine Steve Holden Python 0 09-21-2005 10:29 AM
how come user control added to page doesn't get added to codebehind file? Bennett Haselton ASP .Net 1 11-08-2004 09:26 PM



Advertisments