I have images with different titles:
- !test.png
- 1101.png
- 12345.jpg
- image3.jpg
- image4.jpg
- image5.jpg
- image6.jpg
- image7.jpg
- test_test.png
- test.jpg
- test2.png
I need images with next titles:
- 101.png
- 102.png
- 103.jpg
- 104.png
- 105.png
- 106.jpg
- 107.jpg
- 108.jpg
- 109.jpg
- 110.jpg
- 111.png
Example: 101.png = "1" + "01.png" or "01.jpg", where:
- “1” is variable I enter in the console when I type the gulp command (
gulp 1
) - “01..11.png” (or “01..11.jpg”) are just the names of the images in ascending order
I have this code, gulpfile.js:
import gulp from 'gulp';
import rename from 'gulp-rename';
import del from 'del';
const deleteImages = () => {
return del(['build',], {force:true});
}
const renameImages = () => {
return gulp.src('src/images/*.{jpg,jpeg,png,gif,wepb}')
.pipe(rename({
// code
}))
.pipe(gulp.dest('build'))
}
gulp.task('default', gulp.series(deleteImages, renameImages));
package.json:
{
"name": "gulp-rename-images",
"description": "Task for gulp",
"version": "0.0.1",
"license": "MIT",
"main": "gulpfile.js",
"type": "module",
"devDependencies": {
"gulp": "^4.0.2",
"gulp-rename": "^2.0.0",
"del": "^6.1.0"
}
}
My structure: