Moving files

Kevin D. Clark kclark at CetaceanNetworks.com
Mon Jan 6 12:05:38 EST 2003


mod+gnhlug at std.com (Michael O'Donnell) writes:

>  (Same for Kevin's solution, if you please...)

:  perl -MFile::Find -e 'find(sub{$old = $_; y/ /_/; rename($old, $_);}, "kens-mp3-dir");'

Mine just uses the standard File::Find module.  To find out more about
this, try typing "perldoc File::Find" on your system.

One of the methods in this module is find(), which I have called with
an anonymous subroutine (very much like a lambda function in Lisp) and
a directory list ("kens-mp3-dir" -- I could have specified multiple
directories here if I had wanted).

The find() method calls the subroutine reference that is passed in
(the first argument) over and over, once per <thing> (file, directory,
hard-link, etc...) that it finds in the filesystem traversal (this
should remind you of the standard Unix find utility).

When the subroutine reference is called, the variable "$_" is set to
a name of a <thing> found in the filesystem traversal (*without* the
directory name prepended).  The find() method also takes care of
chdir()'ing your process to the current directory in the filesystem
traversal.



More information about the gnhlug-discuss mailing list