mkdir - Creating folder using perl -
i want create folder using perl same folder perl script exists. created foldercreator.pl requires input parameter folder name.
unless(chdir($argv[0]){ # if dir available change current , unless mkdir($argv[0], 0700); # create directory chdir($argv[0]) or die "can't chdir $argv[0]\n"; # change or stop }
this worked fine if call scipt, in same folder resides. if call in other folder if doesn't work.
eg.
.../scripts/scriptcontainfolder> perl foldercreator.pl new .../scripts> perl ./scriptcontainfolder/foldercreator.pl new
first 1 working fine second doesn't. there way create these folders???
you can use findbin module, give $bin variable. locates full path script bin directory allow use of paths relative bin directory.
use findbin qw($bin); $folder = "$bin/$argv[0]"; mkdir($folder, 0700) unless(-d $folder ); chdir($folder) or die "can't chdir $folder\n";
Comments
Post a Comment