Curs Javascript

Mutare fisier in alt director

Pentru a muta un fisier in Node.js, dintr-un director in altul, poti folosi metoda fs.rename(oldPath, newPath, callback)
Functia moveFile() din urmatorul exemplu poate fi folosita pentru a muta un fisier intr-un alt director.
- Exemplu muta fisierul file1.htm din 'test/' in directorul 'test/dir_1':
//moves the $file to $dir2
var moveFile = (file, dir2)=>{
  //include the fs, path modules
  var fs = require('fs');
  var path = require('path');

  //gets file name and adds it to dir2
  var f = path.basename(file);
  var dest = path.resolve(dir2, f);

  fs.rename(file, dest, (err)=>{
    if(err) throw err;
    else console.log('Successfully moved');
  });
};

//move file1.htm from 'test/' to 'test/dir_1/'
moveFile('./test/file1.htm', './test/dir_1/');

Copiere fisier

Pentru a copia un fisier in Node.js, dintr-un director in altul, poti folosi functia copyFile() din acest exemplu:
//copy the $file to $dir2
var copyFile = (file, dir2)=>{
  //include the fs, path modules
  var fs = require('fs');
  var path = require('path');

  //gets file name and adds it to dir2
  var f = path.basename(file);
  var source = fs.createReadStream(file);
  var dest = fs.createWriteStream(path.resolve(dir2, f));

  source.pipe(dest);
  source.on('end', function() { console.log('Succesfully copied'); });
  source.on('error', function(err) { console.log(err); });
};

//example, copy file1.htm from 'test/dir_1/' to 'test/'
copyFile('./test/dir_1/file1.htm', './test/');

Un Test simplu in fiecare zi

HTML
CSS
JavaScript
PHP-MySQL
Engleza
Spaniola
Ce tip de <input> creaza o paleta de culori pentru selectare culoare?
type="text" type="color" type="date"
<input type="color" name="get_color" />
Care metoda CSS roteste elementul HTML la un anumit numar de grade?
scale() translate() rotate()
#some_id:hover {
  transform: rotate(60deg);
  -ms-transform: rotate(60deg);    /* IE 9 */
  -moz-transform: rotate(60deg);   /* Firefox */
}
Click pe functia care returneaza numarul cel mai mare.
pow() min() max()
var maxn = Math.max(8, 4, 88, 56);
alert(maxn);      // 88
Ce functie previne ca un fisier sa fie inclus mai mult de o data intr-o pagina?
include() include_once() require()
include_once("un_fisier.php");
Care este traducerea corecta pentru: "Ahead of time"?
Peste timp La timp Inainte de vreme
Most people arrived ahead of time.
- Cei mai multi oameni au sosit inainte de vreme (prea devreme).
Indicati traducerea corecta a cuvantului "buenĂ­simo"
mai bun mai putin bun extrem de bun
Este fruto es buenĂ­simo.
- Acest fruct este extrem /nemaipomenit de bun.
Node.js - Mutare si Copiere Fisier

Last accessed pages

  1. Substantivul din limba engleza - The Noun (59599)
  2. Gramatica limbii engleze - Prezentare Generala (217569)
  3. Alphabet and Pronunciation - Alfabetul si pronuntia in limba engleza (60693)
  4. Cursuri limba engleza gratuite si lectii online (66981)
  5. Liste HTML - DL, DETAILS (5905)

Popular pages this month

  1. Curs HTML gratuit Tutoriale HTML5 (363)
  2. Cursuri si Tutoriale: Engleza, Spaniola, HTML, CSS, Php-Mysql, JavaScript, Ajax (347)
  3. Coduri pt culori (231)
  4. Formatare text in pagina html (125)
  5. Gramatica limbii spaniole. Indrumator si prezentare generala (123)