1. File::Path 介绍
The make_path
function creates the given directories if they don't exists before, much like the Unix command mkdir -p
.
The remove_tree
function deletes the given directories and any files and subdirectories they might contain, much like the Unix command rm -r
or del /s
on Windows.
如下是对上边2个函数的封装,用于客户调用
- mkpath( $dir )
- mkpath( $dir, $verbose, $mode )
- mkpath( [$dir1, $dir2,...], $verbose, $mode )
- mkpath( $dir1, $dir2,..., \%opt )
- rmtree( $dir )
- rmtree( $dir, $verbose, $safe )
- rmtree( [$dir1, $dir2,...], $verbose, $safe )
- rmtree( $dir1, $dir2,..., \%opt )
2. 测试用例
#!perl -w use strict; use File::Path; my $FilePath = "E:\\每月工作记录\\2011\\07\\perl目录操作\\AA\\CC\\DD"; eval {mkpath($FilePath)}; if($@) { warn( "Make path [$FilePath] failed:\n$@ "); }