Cross platform problem when using File.separator and getFileList()

In the following code, the macro runs recursively through the top directory selected by getDiroectory(). On a mac (Mac OS 10.12.6,ImageJ1 1.52k), that is. In a Windows environment (Windows 7 Enterprise SP1) recursion does not take place.

		inPath =getDirectory();
		 arrayOfNames = getFileList( inPath );
		for(i=0;i<arrayOfNames.length;i++){
			thisName=arrayOfNames[i];//shows up in Debug window
			if(endsWith(arrayOfNames[i],File.separator)){
				processedFiles=processedFiles+processFolder(inPath + arrayOfNames[i] );
			}
		}

Closer inspection of the arrayOfNames in the debugger of ImageJ1 reveals file names such as “CC7_006/” (=folder!) while, on the other hand, printing File.separator shows a backslash \ symbol. Of course, in the Windows environment, this indeed frustrates recursion as there is no match. This seem to defeat the existense of File.separator.

Is this intended behaviour?

Change

if(endsWith(arrayOfNames[i],File.separator)){

to

if(endsWith(arrayOfNames[i],"/"){

and the macro should work as expected on Windows. “/” is a valid file separator on all operating systems, including Windows.

Here is the description of the getFileList() macro function:

Returns an array containing the names of the files in the specified directory path. The names of subdirectories have a “/” appended. For an example, see the ListFilesRecursively macro at https://imagej.nih.gov/ij/macros/ListFilesRecursively.txt

I’d prefer:

if (File.isDirectory(arrayOfNames[i])) {

in this specific case.

I wasn’t aware of Windows allowing ‘/’ for folder separation, enlightening. Always had believed the Folder.separator was invented to allow for cross platform comparison and creation. I’ll throw the File.separator overboard and use @imagejan’s suggestion.