# Verify if textfile exists (bool)

**URL:** <https://forum.kirupa.com/t/verify-if-textfile-exists-bool/8926>\
**Category:** flash\
**Created:** [December 1, 2002, 6:36am UTC](https://forum.kirupa.com/t/verify-if-textfile-exists-bool/8926 "2002-12-01T06:36:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pissmyran](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Pissmyran](https://forum.kirupa.com/u/Pissmyran)\
**Post date:** [December 1, 2002, 6:36am UTC](https://forum.kirupa.com/t/verify-if-textfile-exists-bool/8926/1 "2002-12-01T06:36:32Z")

</div>

Hey!

Wanted to know if it is possible to make a bool-variable in flash that is set to ‘false’ by default. It then checks if a file exists at a certain location, and if so, the bool-variable is set to ‘true’ ?

Something like:

if (c:/myTextfile.txt == true){_do stuff here_;}

What would be the correct code?

Thanx.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 1, 2002, 12:26pm UTC](https://forum.kirupa.com/t/verify-if-textfile-exists-bool/8926/2 "2002-12-01T12:26:17Z")

</div>

Well, LoadVars would check if that file exists, and if its not, then u could assign the textField something like “Error loading file”, or “TextFile Does’nt exist”.

```php
dataHandler = new LoadVars();
dataHandler.onLoad = function(success) {
if (success) {
myTextBox.text = "File exists";//or u could assign the target variable, it should look like: (without the quotes) "myTextBox.text = this.ExternalVariable"
} else {
myTextBox.text = "File does'nt exist";
}
};
dataHandler.load("textfile.txt");

```

Hope it helps,

yours,  
h88 :bandit:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 1, 2002, 2:31pm UTC](https://forum.kirupa.com/t/verify-if-textfile-exists-bool/8926/3 "2002-12-01T14:31:19Z")

</div>

i don’t think you can’t check if a file exists with Actionscript only. h88’s method is clever, but it’s a workaround. If you really want to know if a file is in a directory, you’ll have to use PHP.

pom 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 1, 2002, 2:33pm UTC](https://forum.kirupa.com/t/verify-if-textfile-exists-bool/8926/4 "2002-12-01T14:33:19Z")

</div>

hum :-\ workaround, does that exist?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 2, 2002, 7:02pm UTC](https://forum.kirupa.com/t/verify-if-textfile-exists-bool/8926/5 "2002-12-02T19:02:23Z")

</div>

H88’s method works, but you have to wait for the file to load completely before Flash knows that the file exists. Somebody else asked this same question in the following thread:

[http://www.kirupaforum.com/showthread.php?s=&threadid=9872](http://www.kirupaforum.com/showthread.php?s=&threadid=9872)

I tried to answer the question there, but basically it involves the getBytesTotal() method, which is much quicker (I think) than loading the whole file.

I’m actually curious to see if that works. If anybody tries it out and it works, plz lemme know. Thanks.

-Al

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 9:49am UTC](https://forum.kirupa.com/t/verify-if-textfile-exists-bool/8926/6 "2002-12-03T09:49:21Z")

</div>

would this work?

if you place the code to upload the variables on the mc instance using an:

onClipEvent (data) {  
}

then the data has to load for that statement to execute (i think)

so you could do something like (excuse the syntax):

fileExists = false //set the boolean

onClipEvent (data) {  
//do stuff  
fileExists = true //set the boolean  
}

// check boolean  
if fileExists = false //the data was not loaded, therefore file doesn’t exist  
else //the file does exist

that’s how i would do it in another language - so i’m hoping it works (not had time to try it yet)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 9:53am UTC](https://forum.kirupa.com/t/verify-if-textfile-exists-bool/8926/7 "2002-12-03T09:53:08Z")

</div>

sorry everybody - i was replying to the first post and suddenly there was all these replies! (i left my browser open for a long time)

i used h88’s code as he set it out in his reply

i just have to assume that if the data isn’t there then the file doesn’t exist
