SOURCE

var fs = require("fs");
// 这里path是你要读取哪一个目录下的所有文件
var path = 'D:/image/产品/广告小门'
fs.readdir(path, function(err, files) {
    // console.log(files);
    let sell_5 = "INSERT INTO `solew4`.`destoon_sell_5` ( `catid`, `mycatid`, `typeid`, `areaid`, `level`, `elite`, `title`, `style`, `fee`, `introduce`, `n1`, `n2`, `n3`, `v1`, `v2`, `v3`, `brand`, `unit`, `price`, `minamount`, `amount`, `days`, `tag`, `keyword`, `pptword`, `hits`, `comments`, `thumb`, `thumb1`, `thumb2`, `thumbs`, `username`, `groupid`, `company`, `vip`, `validated`, `truename`, `telephone`, `mobile`, `address`, `email`, `qq`, `wx`, `ali`, `skype`, `totime`, `editor`, `edittime`, `editdate`, `addtime`, `adddate`, `ip`, `template`, `status`, `linkurl`, `filepath`, `note`, `title2`, `year1`, `origin`, `material`, `size`, `nrong`) VALUES "
    let sell_5_data = "INSERT INTO `solew4`.`destoon_sell_data_5` (`itemid`, `content`) VALUES "
    files.forEach(function(filename, index) {
        //运用正则表达式替换oldPath中不想要的部分
        let itemid2 =  32513
        let itemid = itemid2 * 1 + index * 1 +1
        var oldPath = path + '/' + filename,
            newPath = path + '/' + (itemid2 * 1 +index * 1 + 1) + '.jpg'
            let name = filename.slice(0,-4)
            sell_5 += "( 118116, 4209, 0, 118, 0, 0, '"+name+"', '', 0, '', '', '', '', '', '', '', '', '', 0.00, 0, 0, 3, '', '"+name+"', '', 0, 0, 'http://pinsouw.solew.com.cn/file/upload/202302/20/"+itemid+".jpg', '', '', '', 'zjjiuliang', 7, '浙江九亮智能科技有限公司', 1, 0, '郭经理', '18969137997', '18969127997', '浙江', '', '', '', '', '', 0, 'zjjiuliang', 1676860242, '2023-02-20', 1676860242, '2023-02-20', '122.238.163.126', '', 3, 'show.php?itemid="+itemid+"', '', '', '', '', '', '', '', ''),"
            sell_5_data += "( "+itemid+",'<p><img src=\"http://pinsouw.solew.com.cn/file/upload/202302/20/"+itemid+".jpg\"/></p>'),"
            fs.rename(oldPath, newPath, function(err) {
                if (!err) {
                    // console.log(filename ,"----",itemid * 1 + index * 1 +1)
                }
            })
        })
        console.log(sell_5);
        console.log("===================================");
        console.log(sell_5_data);
})
console 命令行工具 X clear

                    
>
console