Link to home
Start Free TrialLog in
Avatar of jazz250
jazz250

asked on

creating folders

I have a problem using the following code

$PATH='c:\\windows\\main';
sub write
{      
      my ($fileName,$data)=@_;
      open (TOFILE,"+>".$PATH.$fileName) || die "archivo -- $fileName -- no existe en $ENV{PWD} ";;
      print TOFILE $data;
      close TOFILE;      
}

if i execute my function like this:
write ("/text.txt","test data");  # it works fine, it creates text.txt if it wouldnt exists

but if i execute the function:
wirte ("/folder/test/text2.txt","more data");  # it crashes, because  "folder" doesnt exists on my main path and also "test" folder doesnt exists

so, my question is... is there an easy way to create necessary folders if they dont exist on my path??


SOLUTION
Avatar of FishMonger
FishMonger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
use File::Spec::Win32;