Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 7th_zorro), 923 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to read filenames of a dir without limitation #407206
09/09/12 09:19
09/09/12 09:19
Joined: May 2010
Posts: 117
Germany , Dortmund
B
Bone Offline OP
Member
Bone  Offline OP
Member
B

Joined: May 2010
Posts: 117
Germany , Dortmund
Hello,

I want to read the filenames of files in a specified dir.
I tried txt_for_dir and it works but I have to set
a number of strings for the TEXT Object.
I want to get all filenames but the number of files
is not fixed.
Is there any other function that I can use?
Hope someone can help me

Re: How to read filenames of a dir without limitation [Re: Bone] #407210
09/09/12 10:02
09/09/12 10:02
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Try this

Click to reveal..
Code:
//--------------------------------------------------------------------
var txt_for_bigdir(TEXT* txt, STRING* name)
{	if((!txt)||(!name))		return(0);	//invalid parameter/s
	//-----------------------------------------------------------------
	var i, old_len=txt.strings, count;	
	// Automatically flush out all old populated strings
	for(i=0; i<txt.strings; i++)			if((txt.pstring)[i])		
	{	str_remove((txt.pstring)[i]);		(txt.pstring)[i]=0;		}	
	// retrieve directory and verify we got it ALL
	while((count=txt_for_dir(txt,name))==old_len)	//if too small?
	{	//clear strings again AND double TXT.strings size at the time
		for(i=0; i<old_len;	i++)	{	txt_addstring(txt, NULL);
			if((txt.pstring)[i])		{	str_remove((txt.pstring)[i]);
												(txt.pstring)[i]=0;				}	}
		old_len = txt.strings;														}
	//-----------------------------------------------------------------
	return(count);
}
//--------------------------------------------------------------------



Use it in EXACTLTY the same way as you would use txt_for_dir.
But if the TXT is too small it gets auto-extended, and any existing
strings in the array will be wiped clean.

Warning! If it DOES get extended, or the TXT you supplied was too long,
there MAY be unused strings at the end of the TXT.
EG: If you retrieve a directory of 13 items, the TXT may actually be 16 long.

Always rely on the VAR that is returned. It IS an accurate count of how many
filenames were retrieved.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: How to read filenames of a dir without limitation [Re: EvilSOB] #407215
09/09/12 11:22
09/09/12 11:22
Joined: May 2010
Posts: 117
Germany , Dortmund
B
Bone Offline OP
Member
Bone  Offline OP
Member
B

Joined: May 2010
Posts: 117
Germany , Dortmund
Thank you, your code works well!

Re: How to read filenames of a dir without limitation [Re: Bone] #407220
09/09/12 13:59
09/09/12 13:59
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
No problems dude. I just dug it out of my archives...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1