Enumerate with file_next over filenames in directory

Posted By: budfox

Enumerate with file_next over filenames in directory - 12/25/21 16:44

Hi,

currently I am trying to modify the script CSVtoHistory and transform multiple csv files at the same time.

In the manual I found the method file_next(string name) to access the filenames in a directory. The description points out that it can be used to loop well over the filenames in a directory.

Unfortunately, I haven't figured out how to access the next filename in each case, but always get only the first filename in the directory. Does anyone have a suggestion for a solution?

See below my current attempt to get the filenames...


Code

function main() 
{
	int i;
	for (i = 0; i < 10; i++) {
	
	string Name = file_next("CollectedHistory\\*.csv");
	printf("Der Filename lautet: %s \n", Name);
	
	}
}

Posted By: budfox

Re: Enumerate with file_next over filenames in directory - 12/25/21 17:20

I figured it out after trying some more and thought that might be of interest to others.

Code
function main() 
{
	int i;
	for (i = 0; i < 10; i++) {
		
		printf("i ist %i", i);
		if (i == 0) {
			string Name = file_next("CollectedHistory\\*.csv");
			printf("Der Filename lautet: %s \n", Name);
		} 
		else {
			string Name = file_next(0);
			printf("Der Filename lautet: %s \n", Name);
		}
		
	}
}
Posted By: BrainSailor

Re: Enumerate with file_next over filenames in directory - 03/31/22 11:35

Thanks for sharing! I was having the same issue! laugh
© 2024 lite-C Forums