Hi, I've been playing around with a recursive chmod script and came upon something which I don't understand. I have a script which will change directories to 0755 and files to 0644. If I add warnings to the chmod line, the files will be made 0755. ?? What is happening? To simulate what I see, make a test directory say 1, and under that directory make subdirs 1,2,and 3. In 1/1 make a file named test, mode 0000. Make subdirs 1,2,and3 mode 0000 also.

Now here are the two scripts which you put in the top dir at the same level as 1, 2 and 3. The first script when run, will work properly, and make the subdirs 0755 and the test file 0644. The second script,(with warnings on chmod lines) will properly do the subdirs but it makes the test file 0755. What does the warnings do to cause this?

As a second question, why is the recursive chmod so difficult in Perl, where the unix chmod is so simple?

#!/usr/bin/perl -w use strict; use File::Find; my $topdir = shift || '.'; my $filemode = shift || 0644; my $dirmode = shift || 0755; find(\&doit, "$topdir"); #this sub works fine sub doit { return if -d and /^\.\.?$/; chmod($filemode, $_) if (-f $_); chmod($dirmode, $_) if (-d $_); }
#!/usr/bin/perl -w use strict; use File::Find; my $topdir = shift || '.'; my $filemode = shift || 0644; my $dirmode = shift || 0755; find(\&doit, "$topdir"); #this sub causes files to be 0755 instead of 0644 sub doit { return if -d and /^\.\.?$/; chmod($filemode, $_) if (-f $_) or warn $!; chmod($dirmode, $_) if (-d $_) or warn $!; }

In reply to File::Find, chmod and warnings by zentara

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.