perl中的unlink: * unlink Deletes a list of files. On success,it returns the number of files it successfully deleted. On failure,it returns false and sets $! (errno): 1. my $unlinked = unlink 'a','b','c'; 2. unlink @goners; 3. unlink glob "*.bak"; On error,unlink will not tell you which files it Could not remove. If you want to kNow which files you Could not remove,try them one at a time: 1. foreach my $file ( @goners ) { 2. unlink $file or warn "Could not unlink $file: $!"; 3. } Note: unlink will not attempt to delete directories unless you are superuser and the -U flag is supplied to Perl. Even if these conditions are met,be warned that unlinking a directory can inflict damage on your filesystem. Finally,using unlink on directories is not supported on many operating systems. Use rmdir instead. If LIST is omitted,unlink uses $_ . 2:mkpath and rmtree: File::Path 有2个方法:mkpath和rmtree,分别为创建目录和删除目录。 perl语言本身自带了 mkdir和rmdir,那为什么还要选用mkpath和rmtree呢?自带的mkdir只能一次创建一级目录,而mkpath则可以一次创建多级;rmdir必须要求目录为空,而rmtree则任意。总之,File::Path为我们提供了另一种创建和删除目录的机制,由用户自己选用。 说明: a) mkpath(directory,1,0711); 第一个参数为目录名,第二个参数为一个bool值,为真的时候打印每次创建的目录,默认为假,最后一个参数为目录的权限。 b) rmtree(directory,1); 第一个参数为目录名,第二个参数为一个bool值,为真的时候打印删除文件时的一些信息,默认为假,最后一个参数也是一个bool值,为真的时候对没有删除权限的文件直接跳过。 http://perldoc.perl.org/File/Path.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。