Perl-18---目录操作函数
一、读取当前目录: NAME SYNOPSIS ??????? use Cwd 'abs_path'; DESCRIPTION ??? By default,it exports the functions cwd(),getcwd(),fastcwd(),and ? getcwd and friends ??? getcwd ??????? Returns the current working directory. ??????? Exposes the POSIX function getcwd(3) or re-implements it if it's not ??? cwd ??????? The cwd() is the most natural form for the current architecture. For ??? fastcwd ??????? A more dangerous version of getcwd(),but potentially faster. ??????? It might conceivably chdir() you out of a directory that it can't ??? fastgetcwd ??????? The fastgetcwd() function is provided as a synonym for cwd(). ??? getdcwd ??????? The getdcwd() function is also provided on Win32 to get the current ??????? This function simply calls the Microsoft C library _getdcwd() ? abs_path and friends ??? abs_path ??????? Uses the same algorithm as getcwd(). Symbolic links and ??? realpath ??????? A synonym for abs_path(). ??? fast_abs_path ??????? A more dangerous,but potentially faster version of abs_path. ? $ENV{PWD} ????? use Cwd qw(chdir); ??? then your PWD environment variable will be kept up to date. Note that it NOTES ??? *?? Actually,on Mac OS,the "getcwd()","fastgetcwd()" and "fastcwd()" AUTHOR ??? Maintained by Ken Williams <KWILLIAMS@cpan.org> COPYRIGHT ??? This program is free software; you can redistribute it and/or modify it ??? Portions of the C code in this library are copyright (c) 1994 by the SEE ALSO
eg:
一、mkdir()函数: 该函数用于创建一个新目录;调用语法: $Ret? =? mkdir(DirName,Permissions); DirName:这个参数指定需要创建的目录名;可以为字符串直接数或表达式; Permissions:这个参数指定新创建的目录DirName的访问权限;该参数为八进制数; 参数Permissions设定的目录权限值: 调用成功,函数返回非零值(真:1),调用失败,函数返回零值(假); 权限值?????? 权限描述 4000?????????? 运行时设置用户ID 2000?????????? 运行时设定组ID 1000?????????? 粘贴位 0400???????????拥有者读权限 0200?????????? 拥有者写权限 0100???????????拥有者执行权限 0040?????????? 同组用户读权限 0020?????????? 同组用户写权限 0010?????????? 同组用户执行权限 0004?????????? 其它组用户读权限 0002?????????? 其它组用户写权限 0001?????????? 其它组用户执行权限 二、rmdir()函数 $Ret?? =? rmdir(DirName); 该函数用于删除指定的目录,但是这个目录必须是空目录; 调用成功,函数返回非零值(真:1),调用失败,函数返回零值(假:0); 三、opendir()函数: $Ret?? =? opendir(DirHandle,DirName); 类似于Unix/Linux下的C函数opder();用于打开目录文件,以供以后读取目录文件中的内容; DirHandle:目录句柄,与文件句柄类似; DirName:目录名,可以为字符串或表达式; 调用成功,函数返回非零值(真:1),调用失败,函数返回空值(假); 注意:程序中可以使用同名的目录句柄和文件句柄,Perl会根据其上下文环境来确定其类型; 四、closedir()函数 $Ret? =? closedir(DirHandle); 用于关闭已经打开的目录句柄DirHandle;与opendir()配合使用; 调用成功,函数返回非零值(真:1),调用失败,函数返回空值(假); 五、readdir()函数 $FileName? =? readdir(DirHandle); ?或 @FileNames? =? readdir(DirHandle); 该函数用于读取目录文件中的内容,一般位文件名或其子目录下的文件名; 调用成功,则依据等号左边是简单的标量变量还是数组分别返回简单的标量值或数组值;调用失败则返回空值(假:0);也就是说,读取目录文件成功,则依据等号左边的变量是简单的标量变量还是数组分别返回简单的标量值或数组值;读取目录文件失败,则返回空值(假); 六、telldir() 函数: $Position? =? telldir(DirHandle) ; 这个函数与文件操作的tell()函数的功能类似;用于在目录文件头和目录文件尾部之间移动目录文件读位置指针; 调用成功,则返回目录文件的读位置指针所在的当前位置(从目录文件起始位置处到目录文件读位置指针当前位置处的距离:元素个数);调用失败,则返回空值(假); 七、seekdir()函数 $Ret??=? seekdir(DirHandle,Location); 该函数在目录文件起始位置与尾部位置之间随意地移动目录文件读位置指针; 参数Location必须是telldir()函数的返回值; 调用成功,则返回非零值(真:1);调用失败,则返回空值(假); 八、rewinddir()函数 $Ret? =? rewinddir(DirHandle); 该函数用于把读取目录文件的读位置指针从新放回到目录文件的起始位置处,从而可以重新读取目录列表; 调用成功,则返回非零值(真:1);调用失败,则返回空值(假); 九、chdir()函数: $Ret? = chdir(DirName); 调用成功,函数返回非零值(真:1),调用失败,函数返回零值(假:0); 用于改变当前工作目录为参数DirNamer所指定的目录;参数DirName可以为字符串直接数,也可以是值为字符串的简单变量或表达式; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |