Hello,

I would like to check if a given directory is writable for the user who run the script.

 

My first idea is to open a dummy file in ">" mode on that directory and check if 
everythink went ok or not.

Which will look like:

#!/usr/bin/perl
use strict;
use warnings;
my $mydir=$ENV{MY_DIR};

unless(&check_w($mydir)){
 #Continue the job whithout stress ...
 print "I do";
}

sub check_w{
 my($_dir)=(@_);
 eval{
  my $_filename=$_dir."dummy";
  open(FILE,">$_filename") || die "open failed!";
  close(FILE);
  unlink($_filename);
  
 };
 if($@){
  return 1;
 }
 else{
  return 0;
 }
}


 

But I'm not satisfied with this solution.

I think there is an other one better designed.

Could I get input from you please ?

 

Thx,

 

José.



---------------------------------
Yahoo! Mail -- Une adresse @yahoo.fr gratuite et en français !

Reply via email to