Existance Test of 'no file' returns true

SeaCay

Member
Licensed User
Longtime User
Hello All

The code...

Dim aFn as String : aFn = "" ' initialized as nothing

if file.exists("sdcard/media", aFn) then
<do something>
end if

...

seems to always return "true". Even though there is no filename in the exists function.
Why would this be so?

I am aware that as the programmer I should set the filename. Please don't reply telling me to set a filename. My interest is why "file.exists" should return true when there is no file specified.

(tested on LG Optimus Black P970 and Samsung Galaxy Note N7000 both on Android 2.3.4)

regards and many thanks

SeaCay
 

margret

Well-Known Member
Licensed User
Longtime User
When you ask if File.Exists(), it tests for files or folders. When you ask:
file.exists("sdcard/media", aFn), you are asking if /sdcard/media exists and the answer is yes. Because the file is null it does not look for a file it just looks for the folder. I can ask for a file with a path as well like:

B4X:
If File.Exists("", "/mnt/media/Videos/monsters.mp4") Then

This will also return true if the file is there and in that path. Hope this helps.
 
Upvote 0
Top