# How do I get a TFile from a TAbstractFile? #obsidian/api/faq --- If you just called `getAbstractFileByPath` or another API method that returns a `TAbstractFile`, it might be tempting to cast it to a `TFile`. But remember: a `TAbstractFile` can just as easily be a `TFolder`. Even if you're _really_ sure it's a file, the compiler is not. It's much safer to use `instanceof` to be sure it's a `TFile`. ## Sample Code ```ts import type { TFile } from 'obsidian'; /* ... */ const fileOrFolder = vault.getAbstractFileByPath('foo/bar'); if (fileOrFolder instanceof TFile) { // Do something } else { // fileOrFolder is null or a TFolder... handle accordingly } ```