描述
此函數將 DIRHANDLE 指定的目錄中的當前位置重置為目錄的開頭。
用法
以下是此函數的簡單語法 -
rewinddir DIRHANDLE
返回值
此函數在失敗時返回 0,成功時返回 1。
示例
以下是顯示其基本用法的示例代碼 -
#!/usr/bin/perl -w
# 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
相關用法
- Perl reset()用法及代碼示例
- Perl require用法及代碼示例
- Perl return()用法及代碼示例
- Perl readline用法及代碼示例
- Perl reverse()用法及代碼示例
- Perl reverse用法及代碼示例
- Perl reset用法及代碼示例
- Perl rename()用法及代碼示例
- Perl return用法及代碼示例
- Perl ref用法及代碼示例
- Perl rename用法及代碼示例
- Perl read用法及代碼示例
- Perl readpipe用法及代碼示例
- Perl readdir用法及代碼示例
- Perl redo用法及代碼示例
- Perl rindex()用法及代碼示例
- Perl rindex用法及代碼示例
- Perl rand用法及代碼示例
注:本文由純淨天空篩選整理自 Perl rewinddir Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。