如何在一个Perl命令中创建目录和父目录? [英] How do I create a directory and parent directories in one Perl command?

查看:146
本文介绍了如何在一个Perl命令中创建目录和父目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Perl中,如何创建一个子目录,同时创建父目录(如果不存在)像UNIX的mkdir -p命令?

In Perl, how can I create a subdirectory and, at the same time, create parent directories if they do not exist? Like UNIX's mkdir -p command?

推荐答案

use File::Path qw(make_path);
make_path("path/to/sub/directory");

已弃用的mkpath和首选make_path起源于存档的Perl 5 Porters线程中的讨论 here

The deprecated mkpath and preferred make_path stemmed from a discussion in Perl 5 Porters thread that's archived here.

简而言之,Perl 5.10测试在makepath()接口的参数解析中变得尴尬。所以它被替换为一个更简单的版本,采用哈希作为最终参数来设置函数的选项。

In a nutshell, Perl 5.10 testing turned up awkwardness in the argument parsing of the makepath() interface. So it was replaced with a simpler version that took a hash as the final argument to set options for the function.

这篇关于如何在一个Perl命令中创建目录和父目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆