rewinddir DIRHANDLE |
複位開始由DIRHANDLE指定目錄內的當前位置。
0 - 失敗
1 - 成功
在/tmp目錄,並嘗試下麵的例子:
#!/usr/bin/perl -w #by www.gitbook.net # Open the current directory opendir(DIR, "."); # Print all of the directory entries. print("1st Time: \n"); map( print("$_ \n") , readdir(DIR)); print("\n"); # Print message verifying that there are # no more directory entries to read. print("The last file has already been read!\n\n") unless readdir(DIR); # Go back to the beginning. rewinddir(DIR); # Print all of the directory entries again. print("2nd Time: \n"); map( print("$_ \n") , readdir(DIR)); print("\n"); closedir(DIR);
這將產生以下結果:(檢查/tmp目錄)
1st Time:
.
..
testdir
The last file has already been read!
2nd Time:
.
..
testdir