Thanks to everyone for all the thoughtful replies, and taking time to sort out my somewhat lackluster description of the task. :) I tried several methods, including attempting to open the file for writing, but found what seems to be a fairly simple (and most reliable) solution using Perl's 'move' command. The following script can be run as is, provided the user sets the proper input/output directories and desired filetype. On my PC, this script runs with no noticeable effect on CPU usage. Any comments appreciated.
#!/usr/local/bin/perl use strict; use warnings; use File::Basename; # Gives us fileparse() use File::Path; # Gives us mkpath use File::Copy; # Gives us move ############################################################### # NOTE: Set these variables according to your paths and desired # filetype. # # Set input\output paths, filetype, and sleep time. my $inputd = 'C:\temp'; my $outputd = 'D:\test\output'; my $filetype = 'pcm'; my $sleeptime = 1; # seconds to wait between directory reads ############################################################### # Disable print buffer. $| = 1; # Print message to user. print "\nAutomated File Move Utility"; print "\n\nThis script is attempting to move all $filetype files:"; print "\nsource: $inputd\ndestination: $outputd"; print "\n\nPress Ctrl+C to stop...\n\n"; # Repeat indefinitely. while (1) { # Create output directory if it doesn't exist already. if (!-e $outputd) { mkpath ($outputd, 0) or die "\nError - unable to create $outputd: $!\n\n"; } # Get files (full path and name). my @infiles = glob ("$inputd\\*.$filetype"); # Form hash that relates input and output files. my %outfiles; foreach my $inputf (@infiles) { my $basename = fileparse ($inputf, $filetype); $outfiles{$inputf} = "$outputd\\$basename"."$filetype"; } # This block just provides feedback for testing purposes. if (0) { print "\nINPUT:"; foreach (@infiles) {print "\n$_"} print "\nOUTPUT:"; foreach (keys %outfiles) {print "\n$outfiles{$_}"} } # Wait for some time. sleep $sleeptime; # Attempt to move each input file. foreach my $inputf (@infiles) { next if (! move $inputf, $outfiles{$inputf}); print "\nMoved $inputf to $outfiles{$inputf}"; } }

In reply to Re: automated file move by scopey
in thread automated file move by scopey

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.