JAVA和C實現檔案搜尋(遞迴和檔案過濾器)

2021-06-04 22:55:15 字數 1142 閱讀 4562

public static void findfile(file alllist,string endname,listfilenames)  

file files = null;

if((alllist.getabsolutepath().indexof("sd")!=-1)||(alllist.getabsolutepath().indexof("sd")!=-1))

}// 偏歷目錄下的檔案

for(int i=0;i3)

break;

findfile(filearray[i].getabsolutefile(),endname,filenames); //遞迴 }}

} public static class extensionfilefilter implements filefilter

public boolean accept(file file)

string name = file.getname();// find the last

return name.equals(extension);//搜尋特定名稱的檔案

/*int index = name.lastindexof(".");//搜尋特定字尾名檔案

if(index == -1) else

if(index == name.length( ) -1)

else */}

} public static void getpath()

需求一改,立馬就得變換程式,orz,下面是用c實現搜尋,無奈還是很笨啊

void  findfile(const char *dirname,char* desfilename, char* despath)

; dir = (dir*)opendir(dirname);

if(dir == null)

return;

int i;

while ( (d_ent = readdir(dir))!= null )

else if(strcmp(desfilename,d_ent->d_name) == 0)//是普通檔案,比較是否是目標檔案

}closedir(dir);

}

JAVA和C實現檔案搜尋(遞迴和檔案過濾器)

public static void findfile file alllist,string endname,listfilenames file files null if alllist.getabsolutepath indexof sd 1 alllist.getabsolutepath ...

運用遞迴演算法實現檔案搜尋

通過引用命名空間 system.io 可以方便地使用檔案操作的相關類 本例所用到的類 directory 先上 首先宣告全域性變數comleted bool comleted false 有什麼用?先看主體 private void searchfile string directory,strin...

搜尋技術 排列和遞迴

在計算機系統中,遞迴是通過巢狀來實現的,涉及指標,位址,棧的使用。部分例子 1.用stl輸出全排列 include include 包含sort 和next permutation 函式 using namespace std int main sort data,data 4 排序,得到最小序列 ...