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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top