Check for existence of a file

Sorry to be thick, but is there an easy way to check for the existence of a file from within a script?

I’m trying to create a playlist item, but only if the audio file exists. Right now, if the file isn’t there I get a nasty error (maybe I need a try…except around the CreatePlaylistItem?).

Thanks in advance.

BFN
Cad

Have you tried FileExists(‘c:\somefilename’)? I’m not sure if that is exported to the scripting system, but I think it is.

I will try this shortly: thanks.

The problem I’m having occurs when in a try block, I create a new playlist item from file, and the file does not exist. Here’s an example script:

var
   pi: IPlaylistItem;
begin
   try
      pi := Factory.CreatePlaylistItemFromFile('a file name', [fitDuration]);
      systemlog('SUCCESS');
   except
      systemlog('FAILURE');
   end;
end.

I get the SUCCESS message in the system log when I run the script. Why?

BFN
Cad

Because CreatePlaylistItemFromFile will not through an exception when the file does not exist. In other words, it will happily create PlaylistItems for files which are not (already) there. It will just skip the read tags and auto cue etc. parts.

AH. I understand now: no exception thrown if the target file does not exist.

You were correct about FileExists. It … exists in mAirListScript. :wink: And it is perfect for this usage: thanks!

BFN
Cad