in reply to Renaming Sub Dir/Files.

I believe you are right about the -d $fname thing, try this:

if ( -d "$path/$fname" ) {

Also, on a nit-picky note, if you have really big directories, it is more efficient to do a readdir one at a time then to slurp it all into an array

opendir(DIR, $path); @files = readdir(DIR); $ct = 0; while ($fname = readdir(DIR)) { ... # Damian Conway's 'yada, yada, yada' operator :) } closedir(DIR);

Addendum: The same reason that your -d test is not working applies to your renaming problem. As you can see from your output, readdir doesn't return the path, only the filename. You'll probably need to include full paths with your rename() args.

Replies are listed 'Best First'.
Re: Re: Renaming Sub Dir/Files.
by TheDamian (Vicar) on Dec 20, 2001 at 05:29 UTC
Re(2): Renaming Sub Dir/Files.
by dmmiller2k (Chaplain) on Dec 17, 2001 at 21:41 UTC

    ++ehdonhon !!

    When using readdir(), it is necessary to prefix each item read with the $path passed to opendir().

    Also, notice the backticks (backquotes?) in:

    if(`-d $fname`)

    which (if not a typo in JoeCool's original code) effectively send the -d $fname as a command to the shell. Probably not what he intended.

    dmm

    You can give a man a fish and feed him for a day ...
    Or, you can
    teach him to fish and feed him for a lifetime