> -----Original Message-----
> From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-
> win32-users-boun...@listserv.activestate.com] On Behalf Of Barry Brevik
> Sent: 24 October 2011 23:53
> To: perl-win32-users@listserv.ActiveState.com
> Subject: Making directories
>
> I'm still on Perl v5.8.8. I was writing an app today that needs to
> create a sub directory if it does not already exist.
>
> Originally, I used  mkdir( <path> ). Notice that there is no 2nd arg.
> After I did this, the app copies a bunch of files into that sub
> directory, which works fine. HOWEVER, when the same app tries to write
> newer copies of the same files (named the same), I get a "permission
> denied" error.
>
> So I changed the app by setting the umask, and also specifying a
> permissions mask in the mkdir function (see below). I deleted the sub
> directory and ran the new app. Now the sub directory seems to be wide
> open, but when you click on the directory and check properties, it has
> Read Only checked!
>
> I am uncomfortable using unix permission masks on a Windows machine,
> but
> at the same time I would rather not load a module for such a simple
> thing.
>
> Does anyone have advice for me about how they create directories with
> Perl?
>
> Barry Brevik
>
> =====================================
> use strict;
> use warnings;
>
> umask 0;
>
> my $thisPath = "c:\\temp\\megabom\\newdir";
>
> unless (-d $thisPath) {mkdir $thisPath, 0777;}
>
> if (-r $thisPath) {print "  Sub folder is read for everyone.\n\n";}
> if (-w $thisPath) {print "  Sub folder is write for everyone.\n\n";}
> if (-x $thisPath) {print "  Sub folder is execute for everyone.\n\n";}

I understand that the read only attribute on a directory only prevents its 
deletion, but I could be wrong about that. That, and the fact that your first 
copy is successful, suggests that you have an issue with file permissions 
rather than directory permissions. That is the files being copied are read 
only, which is why the second copy fails.

The answer probably depends on how you are copying files. For example, 
according to the doco, File::Copy::cp preserves the original permissions while 
File::Copy::copy sets default permissions on the target.

HTH

--
Brian Raven



Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to