I use the following code to check if a file exists in a folder in sdcard:
//Check if database exists
File fia = new File(Environment.getExternalStorageDirectory()+"/my_folder/db/my_file_1");
if(fia.exists())
{
//do something
}
else
{
Toast.makeText(getApplicationContext(), "Database is not available. Please install it.", Toast.LENGTH_LONG).show();
}
This code works well.
Now I have 5 known files stored in different subfolders of sdcard/my_folder/ as:
1. sdcard/my_folder/db/my_file_1
2. sdcard/my_folder/db/my_file_2
3. sdcard/my_folder/abc/my_file_3
4. sdcard/my_folder/abc/my_file_3
5. sdcard/my_folder/xyz/my_file_5
The problem is that I want to check if all the files exist, then do something. And if any of the above files is not available or missing, then display a Toast message.
I have no idea how to display the Toast message just one time if any of the files does not exist (manually doing this displays the Toast message whenever a file is not available, which is not my wish).
Can you please give a little help? Many thanks.
1 Answer