2016-04-12 238 views
0

在erlang中,我有一個目錄/proj/htdocs/root/jpT/elqstux/16-04-12/[email protected]_09.27.06/auto.suite.sbg_ft_esrvcc_midcall_SUITE.groups.esrvcc_midcall_media_stop_002.logs/run.2016-04-12_09.27.12/log_private/,如何獲取erlang中給定目錄的父目錄名稱?

我想獲得此目錄的父目錄名稱。在這種情況下 ,預期結果是/proj/htdocs/root/jpT/elqstux/16-04-12/[email protected]_09.27.06/auto.suite.sbg_ft_esrvcc_midcall_SUITE.groups.esrvcc_midcall_media_stop_002.logs/run.2016-04-12_09.27.12/

但我儘量dirname(Filename) -> file:filename_all(),但我沒有successed。

所以,我想知道有沒有爲這個目的,這種方法嗎?

回答

1

隨着你的輸入路徑與/結束,你需要調用filename:dirname/1兩次(或者你可以自己將其刪除,並呼籲filename:dirname/1一次):

1> Path = "/proj/htdocs/root/jpT/elqstux/16-04-12/[email protected]_09.27.06/auto.suite.sbg_ft_esrvcc_midcall_SUITE.groups.esrvcc_midcall_media_stop_002.logs/run.2016-04-12_09.27.12/log_private/". 
"/proj/htdocs/root/jpT/elqstux/16-04-12/[email protected]_09.27.06/auto.suite.sbg_ft_esrvcc_midcall_SUITE.groups.esrvcc_midcall_media_stop_002.logs/run.2016-04-12_09.27.12/log_private/" 
2> Expected = "/proj/htdocs/root/jpT/elqstux/16-04-12/[email protected]_09.27.06/auto.suite.sbg_ft_esrvcc_midcall_SUITE.groups.esrvcc_midcall_media_stop_002.logs/run.2016-04-12_09.27.12/". 
"/proj/htdocs/root/jpT/elqstux/16-04-12/[email protected]_09.27.06/auto.suite.sbg_ft_esrvcc_midcall_SUITE.groups.esrvcc_midcall_media_stop_002.logs/run.2016-04-12_09.27.12/" 
3> filename:dirname(filename:dirname(Path)). 
"/proj/htdocs/root/jpT/elqstux/16-04-12/[email protected]_09.27.06/auto.suite.sbg_ft_esrvcc_midcall_SUITE.groups.esrvcc_midcall_media_stop_002.logs/run.2016-04-12_09.27.12" 

你的預期路徑還包括尾隨/,這樣你就可以手動附加爲filename:dirname不包括它:

4> filename:dirname(filename:dirname(Path)) ++ "/" == Expected. 
true 
相關問題