Sunday, March 18, 2018

#1 2005-10-13 01:41:30 pm

From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

How do I know if a file or folder exists?

There are several methods to check for a file or folder's existence. However, the fastest and most reliable is attempting to aliasize its path. Let's go to the sample (with a file, but it's the same for a folder or disk):


set unknownFile to "path:to:this stuff.html"

   alias unknownFile
   --> file exists, go ahead
on error --> file doesn't exist
   --> do whatever
end try

The trick is that an alias is a file or folder which exists. So, if file "this stuff.html" does not exist in folder "to" in disk "path", you will receive an error.



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)