Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: zeroid on June 06, 2015, 12:55:53 AM

Title: File & Directory functions?
Post by: zeroid on June 06, 2015, 12:55:53 AM
1. How do i check if the file exist? (in c# File.exist("image.jpg"))

2. How do i get a list of files in that particular folder (directory.getFiles(), returns an array of full filepath)

Title: Re: File & Directory functions?
Post by: liquid8d on June 07, 2015, 07:18:37 AM
Not sure if there is another way to check if a file exists but you can do:
Code: [Select]
if ( exists( "myfile") )
{
   //file exists
}

function exists( filename )
{
   try
   {
      f = file( "myfile", "r" )
      return true;
   }
   catch ( e )
   {
      print( "couldn't open file: " + filename + "\n" );
   }
   return false;
}

For a directory listing, include the file module and use DirectoryListing:
Code: [Select]
fe.load_module("file");

local dir = DirectoryListing( path );
foreach ( f in dir.results )
{
   print( "file: " + f + "\n" );
}
Title: Re: File & Directory functions?
Post by: zeroid on June 07, 2015, 07:20:34 AM
Thank you.
could you have a look at my other post?
http://forum.attractmode.org/index.php?topic=227.0 (http://forum.attractmode.org/index.php?topic=227.0)