sri1230 has asked for the wisdom of the Perl Monks concerning the following question:

I am experiencing some wierd issue with this piece of code. If there are multiple bad files in the source the move works fine with all but one file. The is the error i get. I dont understand how this could be a permissions issue when it works for all other files but one This is the error i see

can't copy bad file \\<server>/Data/DATA_DIR/INBOUND/TESTMD5/TESTFILE4.txt to import folde r \\server\Data\DATA_DIR\INBOUND\TESTMD5\import\TESTFILE4.txt.DUPLICATE: Permission denied

for my $file (@bad_files) { (my $volume, my $SrcDir_part, my $SrcPattern) = File::Spec->splitp +ath($file); my $outdir=File::Spec->catdir($SrcDir_part,"import"); $outdir = File::Spec->catdir($volume,$outdir); my $bad_file = File::Spec->catdir($outdir, $SrcPattern); $bad_file = "$bad_file\.DUPLICATE"; move($file, $bad_file) or $logger->logdie("can't copy bad file $fi +le to import folder $bad_file: $!"); #unlink $file or die "$? : $! - error"; push(@attach_list,"$bad_file"); }

Replies are listed 'Best First'.
Re: Wierd move issue
by ikegami (Patriarch) on Feb 25, 2010 at 17:27 UTC
    It could be that the src or dst file is open and locked by another process. You can use Process Explorer (free download from MS) on the server to find if a process has a handle to the file in question.
      I checked that nothing is open . I was using foreach earlier and some one told me that its deprecated and had some issues. I changed that to for. And when i use copy followed by unlink the copy works but the unlink does not.

        I was using foreach earlier and some one told me that its deprecated and

        They are wrong. foreach is not deprecated. "for" and "foreach" are two keywords that mean the same thing to Perl.

        I checked that nothing is open .

        Aside from that fact that it's impossible for nothing to be open, how did you determine this?

        unlink does not

        So the file is read-only, or you don't have permissions to delete it, or some process holds a share or delete lock on the file.

Re: Wierd move issue
by BrowserUk (Patriarch) on Feb 25, 2010 at 18:07 UTC
    \\<server>/Data/DATA_DIR/INBOUND/TESTMD5/TESTFILE4.txt

    I suspect that it is the mixed backslashes and forward slashes and/or angle brackets that the OS doesn't like.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.