看板 Perl 關於我們 聯絡資訊
我遇到一個奇怪的問題 我想先用opendir把目錄下的檔名讀出來之後開檔 但是都會出現Permission denied的錯誤訊息 但是把開檔那兩行刪掉就不會有問題,讀的到檔案名子 但是只要一open就有問題 我是用管理者帳號登入的 資料夾的權限也都開放給everyone OS 是 XP Pro 我不想把檔案名存起來,因為檔案很多 能請各位幫我解決一下這個問題嗎 謝謝 下面是我的程式 opendir DIR, "."; while($infile = readdir(DIR)){ print "$infile\n"; # open(FHD, $infile) || die "$!\n"; # close(FHD); } closedir DIR; Modified version: opendir DIR, "."; while($infile = readdir(DIR)){ print "$infile\n"; next if($infile='.'); #加上這行就好了 open(FHD,$infile) || die "$!\n"; close(FHD); } closedir DIR; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.62.191.115 ※ 編輯: aleelyle 來自: 61.62.191.115 (10/22 20:36)
giacch:我在 FreeBSD 上 run 沒出現錯誤... XDDD 10/22 23:22
giacch:猜測... 第一個 $infile 是 . 所以 open 目錄 就 die 了~ 10/22 23:24
※ 編輯: aleelyle 來自: 61.62.191.115 (10/23 00:53)
aleelyle:果然是這樣!太感謝了 另附上修改過的版本 10/23 00:53
Seshon:我猜你還會遇到 .. 兩點的問題 10/23 22:56
Seshon:可試一下glob這個function, 就可以避掉 10/23 22:57
giacch:我發現一個問題耶... 後來修改的地方... 10/23 23:35
giacch:$infile=',' 是 true 唷~ 會一直 nxet (爆 10/23 23:38
giacch:$infile='.' (我按錯key了... = = 10/23 23:39
Seshon:想一下這段$infile='.'對, 還是這樣對$infile = = '.' 10/24 21:07
Seshon: 還是$infile eq '.' 對 10/24 21:08