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.$fileNa me) || 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??
$PATH='c:\\windows\\main';
sub write
{
my ($fileName,$data)=@_;
open (TOFILE,"+>".$PATH.$fileNa
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",
so, my question is... is there an easy way to create necessary folders if they dont exist on my path??
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
use File::Spec::Win32;