getAbstractFileByPath case sensitive but Create is not

Hi, I’m creating an import plugin and trying to check if a file exists before I create it. I’m not sure I’m going about it in the right way, however, I think I’ve found a consistency problem that can create an issue regardless.

const filename = "example";
let fileRef = vault.getAbstractFileByPath(`${filename}.md`);
if(fileRef === undefined || fileref === null) {
   vault.create(`${filename}.md`, '');
}

With code similar to above, I’ve noticed that getAbstractFileByPath is case sensitive, while vault.create isn’t (because two files with the same spelling but different cases can’t exist).

This means that when I test if the file exists, I’m led to believe it doesn’t but then when I try and create the file, I get a file exists error.
(Because example.md doesn’t exist, but Example.md does.

I’m a bit stuck with this because the nature of these imports I’m dealing with often have the same title, so I need to know when to add a version number to the filename.

Am I mistaken, is there a reason it works like this?

btw. This is how I’ve gotten around it:

async function createNewEmptyMdFile(path: string, version: number = 1) : Promise<TFile> {
	let fileRef: TFile;

	try {
		if(version == 1) {
			fileRef = await plugin.app.vault.create(`${path}.md`, '');
		} else {
			fileRef = await plugin.app.vault.create(`${path} (${version}).md`, '');
		}

	} catch {
		fileRef = await createNewEmptyMdFile(path, version+1);

	}
	

	return fileRef;
}