I don't use perl much. I tried to use it to rename some files and I can't get the rename function to work. The problem seems to be file permissions, but even if I use sudo, or chmod the permissions to 755, it still won't work. Does this have something to do with OSX and Darwin? I am running 10.6.2 on an Intel Macbook.

My code (the directory "kennel" contains two files: cat1, cat2):

opendir(DIR,"kennel"); while ($file = readdir(DIR)) { next unless $file =~ /cat/; my $newfile = $file; $newfile =~ s/cat/dog/; rename($file, $newfile) || print "Don't have permission to rename. +\n"; } closedir(DIR);
When run, this code prints the error message (i.e. does not rename files)

In reply to rename doesn't work on OSX? by mmfuller

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.