java - Return statement not working -
can help me fixing problem. have function checks if file nowadays in particular path. function checks if filenames match , paths match.(a file particular name nowadays in multiple locations). please find below code.
memberpath static variable contains relative path. file_path static variable gets updated when match has been found.
my problem function finds match breaks out of for-loop comes homecoming statement goes loop. can help me prepare code 1 time match found returns bac calling position.
public static string traverse(string path, string filename) { string filepath = null; file root = new file(path); file[] list = root.listfiles(); (file f : list) { if (f.isdirectory()) { traverse(f.getabsolutepath(), filename); } else if (f.getname().equalsignorecase(filename) && f.getabsolutepath().endswith(memberpath)) { filepath = f.getabsolutepath(); file_path = filepath; break ; } } homecoming filepath; }
add :
return traverse(f.getabsolutepath(), filename);
to homecoming value call.
as pointed out - can homecoming value instead of break.
java
No comments:
Post a Comment