Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

RE: Re: Mode of created files

by setantae (Scribe)
on Mar 28, 2000 at 02:32 UTC ( [id://6283]=note: print w/replies, xml ) Need Help??


in reply to Re: Mode of created files
in thread Mode of created files

I'm not sure that I do want umask:
 To clarify, the mode I need the files created with is unknown.
What I'm trying to do is to check the mode of a file that already exists, and then create other files that have the same mode (i.e., I don't know what mode the files need to be created with yet).
So my logic would possibly go something like:
1) get mode of file1; 2) create files file2, file3,..., fileN; 3) chmod files file2,..., fileN to the same mode as file1.
If that makes any more sense...

Replies are listed 'Best First'.
RE: RE: Re: Mode of created files
by btrott (Parson) on Mar 28, 2000 at 02:53 UTC
    You could do that, sure... in that case you just need to use stat to get the mode of the file.
    my $mode = (stat "foo")[2];
    But I think you could use umask, still... and it may make it easier. Try something like this:
    my $mode = (stat "foo")[2]; my $mask = 777 - join '', (($mode&0700)>>6, ($mode&0070)>>3, ($mode&0007)); umask oct $mask;
    I'm not sure if this is absolutely right (please someone correct me if it isn't), but it seemed to work for the test cases I tried.
      Man, I wish I could vote you up twice for this little gem:join '', (($mode&0700)>>6, ($mode&0070)>>3, ($mode&0007)); That's exactly what I was after!

      setantae

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://6283]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-25 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found