I have written a Perl application that downloads several directories to a temporary download folder before doing some operations and then moving subfolders from the download folder to various locations. The problem is that other people browse through the download folder during the ftp transfer and occasionally cause the dirmove function to fail.

The download folder gets created with a timestamp ( 12 digits in the actual application) so it is unique and easy to find if something goes wrong. I read about flock but it doesn't seem to work for directories when I tried it. I'm thinking about setting the hidden bit (Windows 2008 server) during the download. I already have a function that is triggered by __DIE__ so I could unhide it if something happens.

The code below allowed me to recreate the problem. I found if I opened the directory in Windows Explorer then there was no error. If I opened the file with Notepad at the target location my script would move the file but then die without moving the directory. By changing to the directory in a command prompt before the dirmove then I get the "Permission Denied" error and nothing is moved.

Has anyone else dealt with this? Any suggestions?

#!/usr/bin/perl use warnings; use strict; use File::Copy::Recursive qw( dirmove fmove ); # 'D:/Users/bas/ftp_20110722/1/logs/ACREROCK TIE_SUB_log. +txt'; my $frompath = 'D:/Users/bas/ftp_20110722'; my $topath = 'D:/Users/bas/logs'; my $target = '/1/logs'; print "\nabout to move $frompath$target\n"; print "press <enter>"; <>; dirmove "$frompath$target", "$topath$target" or die "can't move $frompath$target to $topath$target :",$!;

Results in this:

d:\Users\bas>perl dirmove_test.pl about to move D:/Users/bas/ftp_20110722/1/logs press <enter> can't move D:/Users/bas/ftp_20110722/1/logs to D:/Users/bas/logs/1/log +s :Permiss ion denied at dirmove_test.pl line 22, <> line 1.


In reply to Permission denied error from dirmove function of File::Copy::Recursive. by Gulliver

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.