Search code examples
javafiledir

How to check if directory contains file which name contains certain string?


I have to find a file ard12333.txt but the number part is variable so I should check if the file contains the string "ard" and then extrapolate the number part. How to do that?


Solution

  • Steps for your work :

    1) Fetch the file name from directory.

    2) Check whether it contains ard or not.

    3) If yes, then convert the rest of file name without extension to Integer or Long or whatever Number. If No, go to step 1 to check next file if any.

    4) If value of variable and converted number matches, wooohhooo you are done. Break the loop and do whatever you want.