Answer the question
In order to leave comments, you need to log in
How to give a folder the name of a file/s in it in gulp?
Hello! What you need to do is to have Gulp take the file(s) and move it to a folder that will take the name of the file that was moved into it.
For example, there are three files: "example.ttf", "example.otf" and "example.woff"
You need to configure gulp so that it takes these files and moves them to a folder that will take a name depending on the name of those in it files, in this case, "example"
Can you please tell me if this can be done through gulp at all? And how? I couldn't find anything in google and yandex.
Thank you!
Answer the question
In order to leave comments, you need to log in
const Folder = './fonts/';
const fs = require('fs');
const path = require('path');
fs.readdir(Folder, (err, files) => {
files.forEach(file => {
let fileName = path.parse(file).name
if (!fs.existsSync(Folder + fileName)) fs.mkdirSync(Folder + fileName);
fs.rename(Folder + file, Folder + fileName + '/' + file, function(err) {
if (err) console.log('ERROR: ' + err);
});
});
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question