第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 gulp.rename() 調(diào)用中使用來(lái)自早期 gulp.src 的文件名

在 gulp.rename() 調(diào)用中使用來(lái)自早期 gulp.src 的文件名

縹緲止盈 2022-01-20 20:49:08
我在文件夾中有一個(gè) zip 文件,我想提取其中一個(gè)(壓縮的)文件并source file basename + .xml在文件夾中給它一個(gè)文件名模式./sourcefiles_unpacked/./sourcefiles/test.zip=>./sourcefiles/test.zip./sourcefiles_unpacked/test.xml解壓縮和過(guò)濾與 gulp-unzip 配合得很好,但是我不確定如何從 gulp.src 調(diào)用中訪問(wèn)文件名。gulp.task('unzip-filtered-rename', function() {  return gulp.src(paths.unzip_sourcefiles)    // .pipe(debug())    .pipe(plumber({      errorHandler: notify.onError('unzip-filtered-rename error: <%= error.message %>')    }))    .pipe(changed(paths.excel_targetdir_local_glob, {      extension: '.xml'    }))    .pipe(unzip({filter : function(entry){return minimatch(entry.path, "contents.xml")}}))    .pipe(gulp.rename(function(path){               // ? What do I put here to rename each target file to         // ?   its originating zip file's basename?    })) //   "==> test.xml",    .pipe(gulp.dest(paths.sourcefiles_unpacked)) //   sourcefiles_unpacked: "./sourcefiles_unpacked/"});一旦 gulp.rename() 被調(diào)用,塊就被重命名為它在 zipfile 中的名稱。如何訪問(wèn)或存儲(chǔ)早期管道的文件路徑以用于重命名函數(shù)調(diào)用?如果路徑包含 glob“./sourcefiles_unpacked/”,是否正確配置了 gulp.dest?
查看完整描述

1 回答

?
一只斗牛犬

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊

試試這個(gè):


const glob = require("glob");

const zipFiles = glob.sync('sourcefiles/*.zip');


gulp.task('unzip-filtered-rename', function (done) {


  zipFiles.forEach(function (zipFile) {


    const zipFileBase = path.parse(zipFile).name;


    return gulp.src(zipFile)

        // .pipe(debug())

        //   .pipe(plumber({

        //     errorHandler: notify.onError('unzip-filtered-rename error: <%= error.message %>')

        //   }))

        //   .pipe(changed(paths.excel_targetdir_local_glob, {

        //     extension: '.xml'

        //   }))

        //   .pipe(unzip({filter : function(entry){return minimatch(entry.path, "contents.xml")}}))

        .pipe(rename({

            basename: zipFileBase,

        }))

        .pipe(gulp.dest("./sourcefiles_unpacked")) //   sourcefiles_unpacked: "./sourcefiles_unpacked/"

    });

    done();

});

我注釋掉了您僅出于測(cè)試目的而做的其他事情。通過(guò) forEach 或 map 運(yùn)行每個(gè)文件允許您在流的開(kāi)頭設(shè)置一個(gè)變量,該變量將在以下流中可用。


另請(qǐng)參閱如何使用 Gulp 解壓縮同一文件夾中的多個(gè)文件,以獲取有關(guān)設(shè)置要在流中使用的變量的更多討論。


查看完整回答
反對(duì) 回復(fù) 2022-01-20
  • 1 回答
  • 0 關(guān)注
  • 236 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)