Iterate through all files in a folder

Hello, I am using the following code to perform actions on a single file in a folder. What I would like to do is iterate through all the files in a folder. How would that be accomplished in AFL?

fh = fopen( "D:\\ABData\\testdata.csv", "r" ); 
if( fh ) 
	while( ! feof( fh ) )
		...function to do something...		
	fclose( fh );
	printf( "ERROR: file can not be found\n" );

Kind regards.

Use fdir()

The example codes that iterate thru all files in the folder are included in the page linked above.

1 Like

I just came across this for the fdir function. I only copied the example code into AB and got these three errors. With double slash \\ it works fine for me.
Is this a mistake on my side or did this change over the years?


You should always use double backslash \\ for paths to files/directories in AFL.
I believe one backslash got removed in the code example of manual because of HTML. See your quote in my post. As you can see one backslash has disappeared also because of not being within code tags.

1 Like

I do always use double backslash in functions I know. This one I used the first time and was playing around with the example.
And indeed I edited my post afterwards to three backslashes to see two in my post, this could indeed be it.

Unfortunately some server side software removes double backslashes. The same happens
when you copy-paste code to this forum WITHOUT code tags. That is why using code tags is essential.

When posting the formula, please make sure that you use Code Tags (using </> code button) as explained here: How to use this site.

Using code button

Code tags are required so formulas can be properly displayed and copied without errors.

In ALL strings, not only paths, a SINGLE backslash MUST be written as \\
That is common convention in AFL and EVERY string must use it.