mkdir-p.pl 550 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/local/bin/perl
  2. # mkdir-p.pl
  3. # On some systems, the -p option to mkdir (= also create any missing parent
  4. # directories) is not available.
  5. my $arg;
  6. foreach $arg (@ARGV) {
  7. $arg =~ tr|\\|/|;
  8. &do_mkdir_p($arg);
  9. }
  10. sub do_mkdir_p {
  11. local($dir) = @_;
  12. $dir =~ s|/*\Z(?!\n)||s;
  13. if (-d $dir) {
  14. return;
  15. }
  16. if ($dir =~ m|[^/]/|s) {
  17. local($parent) = $dir;
  18. $parent =~ s|[^/]*\Z(?!\n)||s;
  19. do_mkdir_p($parent);
  20. }
  21. mkdir($dir, 0777) || die "Cannot create directory $dir: $!\n";
  22. print "created directory `$dir'\n";
  23. }