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. ThanksPhil#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"; }
In reply to testing if a file is open/in use before moving by philc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |