# Detects if a file exists AND if it's empty

**URL:** <https://forum.kirupa.com/t/detects-if-a-file-exists-and-if-its-empty/201630>\
**Category:** flash\
**Created:** [September 23, 2006, 10:31am UTC](https://forum.kirupa.com/t/detects-if-a-file-exists-and-if-its-empty/201630 "2006-09-23T10:31:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayme65](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@Jayme65](https://forum.kirupa.com/u/Jayme65)\
**Post date:** [September 23, 2006, 10:31am UTC](https://forum.kirupa.com/t/detects-if-a-file-exists-and-if-its-empty/201630/1 "2006-09-23T10:31:50Z")

</div>

I have to load a text file.  
First I want to detect if the file exists or not, so I use “if (rawTxt == undefined)”.

Now, if the file exists and contains data, the condition n°2 is met…it’s OK!  
But now, if the file exists BUT is empty it doesn’t meet the condition n°2…why?  
It’s not “undefined” neither “not undefined” since any trace action accours.

In other words, how can I check that a text file exists…AND that it’s empty or not  
(so that I can add a branch if that condition is met?)  
Try by yourself with an empty text file named “Favorites.ini”.

Thanks very much!

```auto

var loadFavorite = new LoadVars();
loadFavorite.onData = function(rawTxt:String) {
 if (rawTxt == undefined) {
  trace("It's undefined");
 } else {
  trace("It's OK");
 }
};
loadFavorite.load("Favorites.ini");

```

same behavior with an onLoad function

```auto

var loadFavorite = new LoadVars();
loadFavorite.onLoad = function(success:Boolean) {
 if (success) {
  trace("onLoad success")
 } else {
  trace("onLoad success")
 }
};
loadFavorite.load("Favorites.ini");

```
