Author Topic: File & Directory functions?  (Read 5276 times)

zeroid

  • Full Member
  • ***
  • Posts: 30
    • View Profile
File & Directory functions?
« 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)


liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: File & Directory functions?
« Reply #1 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" );
}

zeroid

  • Full Member
  • ***
  • Posts: 30
    • View Profile
Re: File & Directory functions?
« Reply #2 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