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

Discussion in 'Perl Misc' started by andy, Oct 5, 2007.

  1. andy

    andy Guest

    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.
     
    andy, Oct 5, 2007
    #1
    1. Advertising

  2. andy

    Guest

    andy <> wrote in message-id: <>

    >
    > 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
    }
     
    , Oct 5, 2007
    #2
    1. Advertising

  3. andy

    Ben Morrow Guest

    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
     
    Ben Morrow, Oct 5, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. karim
    Replies:
    1
    Views:
    791
    George Ter-Saakov
    Jun 26, 2003
  2. Bennett Haselton
    Replies:
    1
    Views:
    543
    John M Deal
    Nov 8, 2004
  3. Nico Grubert
    Replies:
    1
    Views:
    2,638
    Markus Rosenstihl
    Sep 21, 2005
  4. Steve Holden
    Replies:
    0
    Views:
    423
    Steve Holden
    Sep 21, 2005
  5. Replies:
    26
    Views:
    2,175
    Roland Pibinger
    Sep 1, 2006
Loading...

Share This Page