加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

ulink,mkpath,rmtree

发布时间:2020-12-16 00:39:30 所属栏目:大数据 来源:网络整理
导读: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 "
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读