in reply to rename and create directories

You'll have to create the directories separately from the rename() because rename() doesn't do that. Read perldoc File::Path. Look for the mkpath routine.

Replies are listed 'Best First'.
Re^2: rename and create directories
by gaal (Parson) on Nov 30, 2004 at 21:34 UTC
    Note that in addition, rename doesn't (typically) span filesystems; so you end up needing File::Copy::move or equivalent, too.
Re^2: rename and create directories
by Anonymous Monk on Nov 30, 2004 at 21:43 UTC
    Thanks guys, I had suspected that rename didn't support that but didn't know what alternative to seek. Now I'm stuck tryiing to make a regex that will chop the filename off of a directory string like c:\bla\did\dy\blah.txt to be c:\bla\did\dy. Can you answer this one as fast?

    Currently I am splitting the string on "\" and reconstructing it without the last array element. Surely there is a better way.
      Currently I am splitting the string on "\" and reconstructing it without the last array element. Surely there is a better way.

      Indeed there is, use File::Basename, and thy foot shall step upon the path of goodly ways.

      ### ... sample snippet ... my ($basename,$path,$extension) = File::Basename::fileparse($fullpath,qw(.txt));