Game Development Community

findFirstFile

by Nigel Kelly · in Torque Game Builder · 09/15/2009 (1:56 pm) · 4 replies

Hi

I've looked at lots of threads on findFirstFile and my code still doesn't find files.

I'm using TGB on Vista.

%pattern = "*/game/gameScripts/" @ "*.cs";
%file = findFirstFile(%pattern);
echo(%file);

Also tried with -
%pattern = "~/game/gameScripts/" @ "*.cs";
%pattern = "./game/gameScripts/" @ "*.cs";

But still no joy.

Anyone any ideas?

Thanks



#1
09/15/2009 (9:00 pm)
Try this:
%pattern = expandFileName( "game/gameScripts/*.cs" );
%file = findFirstFile( %pattern );
#2
09/16/2009 (9:05 am)
Phil - that's great. It works.

Just one more question. The file returned is actually the last file in the directory (which is sorted by date modified). I've heard before that the last object in a list is usually returned first for efficiency. Is this the case here? Do you know how findFirstFile sorts/orders the files it searches in a directory? I guess what features of the file make it the first file?

Much appreciated.
#3
09/16/2009 (7:44 pm)
I always thought that it was sorted by name. If your code relies on the file list being ordered, I suggest finding the files, sorting them in the order that you want and then use them.

I see that you've got TGB Pro, it would be best to do that kind of thing in source for efficiencies sake.
#4
09/17/2009 (5:53 am)
Thanks again.