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 vremeMost 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 bunEste fruto es buenĂsimo.
- Acest fruct este extrem /nemaipomenit de bun.