revered monks... I apologize if this question is too basic ... Using Windows XP in a network environment. Perl 5.8.7. Writing an application that searches for directories and moves the directory and its content from one directory to another on the same server. The code is basic stuff but here's the rub...in Windows (and I imagine Unix OS and Mac OS) if a file is open and the script attempts to move the directory, it will, on Windows at least, move the contents of the directory that are not open and then leave the single file that is open Is there a way to test whether a file is open/in use prior to copying or moving the file? The standard file x-tests do not raise any flags for when the file is open/in use. I've run through the x-tests using the simple code below but they all return "okfine" when the file is open except for -t - but I get "doh" regardless of whether the file is open or not. Thanks
#x tests to see if a file is open and can be moved use File::Copy; $dir = "C:\\Documents and Settings\\philc\\Desktop\\01_ testing\\Copy" +; $file = "test.pdf"; $destination = "C:\\Documents and Settings\\philc\\Desktop\\01_ testin +g\\Copy\\Xtests2"; #test all file tests -e, -r, -w, -o,-l.-p,-s,-t, if(-e $file){ copy($file,$destination); print "okfine\n"; }else{ print "doh!\n"; }
Phil

In reply to testing if a file is open/in use before moving by philc

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.