“File Salin NodeJS” Kode Jawaban

File Salin NodeJS

const fs = require('fs');

// File destination.txt will be created or overwritten by default.
fs.copyFile('source.txt', 'destination.txt', (err) => {
  if (err) throw err;
  console.log('source.txt was copied to destination.txt');
});
Nerdy Girl

Node Filesystem mengubah direktori file

const {promisify} = require('util');
const fs = require('fs');
const {join} = require('path');
const mv = promisify(fs.rename);

const moveThem = async () => {
  // Move file ./bar/foo.js to ./baz/qux.js
  const original = join(__dirname, 'bar/foo.js');
  const target = join(__dirname, 'baz/qux.js'); 
  await mv(original, target);
}

moveThem();
Zacarias Zack

Salin teks dari file ke file lain di JavaScript dengan FS

'use strict';

import fs from 'fs';

let fileContent = 'Anything what you want';
let message = fs.writeFileSync('message.txt', fileContent);

function copyContent(fileName: string, dest: string): boolean {
  try {
    fs.copyFileSync(fileName, dest);
    console.log(dest);
    return true;
  } catch (err) {
    return false;
  }
}

console.log(copyContent('message.txt', 'destination.txt'));
Creepy Gábor

Jawaban yang mirip dengan “File Salin NodeJS”

Pertanyaan yang mirip dengan “File Salin NodeJS”

Lebih banyak jawaban terkait untuk “File Salin NodeJS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya