rename a csv file in typescript

To rename a csv file in TypeScript, we can use the fs module provided by Node.js. Here is an example code snippet:

index.ts
import * as fs from 'fs';
import * as path from 'path';

const oldFilePath: string = path.join(__dirname, 'oldFileName.csv');
const newFilePath: string = path.join(__dirname, 'newFileName.csv');

fs.rename(oldFilePath, newFilePath, (err) => {
  if (err) throw err;
  console.log('File Renamed!');
});
301 chars
11 lines

In this example, we first define the oldFilePath and newFilePath variables using the path.join() method to create the absolute file paths. Then, we use the fs.rename() method to rename the file. If an error occurs, we throw it. Otherwise, we log the success message to the console.

related categories

gistlibby LogSnag