find the name of a file in typescript

To find the name of a file in TypeScript, you can use the path module provided by Node.js. First, import the path module:

index.ts
import * as path from 'path';
30 chars
2 lines

Then, you can use the path.basename() method to get the name of the file:

index.ts
const filePath = '/path/to/file.txt';
const fileName = path.basename(filePath);

console.log(fileName); // Output: file.txt
124 chars
5 lines

In the above example, the path.basename() method takes the file path as an argument and returns only the name of the file.

gistlibby LogSnag