看板 Perl 關於我們 聯絡資訊
各位大大 以下是我的code my $file; my @file_list = <./test/*.AAA>; foreach $file (@file_list){ print "$file\n"; } 我要找test目錄下要找*.AAA檔名 可是此結果會變成 ./test/aaa.AAA ./test/bbb.AAA 我希望找到結果只是檔名不含它的路徑 該如何修正? 也就是說 每個$file變數分別為aaa.AAA bbb.AAA 請大大幫我 ※ 引述《jeffreychen ()》之銘言: : 各位大大 : 請問,如果我要列出BBB路徑下所有.AAA的檔案 : 並將這些結果被到陣列中 : 請問該如何寫呢. : 例如目錄 BBB下有檔案a.AAA b.AAA c.AAA d.BBB : 希望陣列的結果為[a.AAA b.AAA c.AAA] : 麻煩大大指點 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.248.184.238
iFEELing: hint : chdir 03/07 19:39
flu:加上 use File::Spec::Functions qw[splitpath]; 03/09 01:11
flu:再把print那列改成 print( (splitpath($file))[-1], "\n" ) 03/09 01:11
pshuang:如果是 linux 系統的話, `basename $file` 就只會取檔名 04/29 13:33