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

A

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.
 
Q

QoS

andy said:
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
}
 
B

Ben Morrow

Quoth andy said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top