2017-01-03 42 views
1

我想遞歸地往回走一個目錄,直到我找到一個特定的父文件夾。Java;去備份一個文件樹,直到一個特定的文件夾

基本上我後是

while (!child.getParentFile().equals(greatGrandparent)) { 
     // keep going backwards until it does 
    } 

child可能是10,20,50個水平下方greatGrandparent

我能在網上找到跟它啓動和祖父母和檢查每個孩子,直到我找到了我正在尋找的孩子,但是可能有一百萬名祖父母下的孩子,我不想在他們知道自己需要回樹的時候檢查他們,如果這樣做有道理的話。

這是否有標準模式?

+0

你是說繼續,直到父母和祖父母是相同的?那是什麼代碼看起來像.. –

回答

1

這有什麼錯

while (!child.getParentFile().equals(greatGrandparent)) { 
    child = child.getParentFile(); 
} 
+0

呃你是對的。腦屁! –

0

聽起來像是你正在尋找簡單:

while (!child.getParentFile().equals(greatGrandparent)) { 
    child = child.getParentFile(); 
} 

如果這不是你在找什麼,你需要更好地解釋你的問題。

相關問題