记录dos批量复制文件目录,批量替换文件内字符

  1. 移动目录
@echo off
set /p count=复制多少个:
if %count% gtr 1 (
for /l %%i in (1,1,%count%)do ( 
	echo %%i
	if %%i LSS 10 (
		xcopy "E:\SyncCode\AutoControl\scripts\本地打包\001" "E:\SyncCode\AutoControl\scripts\本地打包\00%%i" /E/Y/I
	) else (
		if %%i LSS 100 (
			xcopy "E:\SyncCode\AutoControl\scripts\本地打包\001" "E:\SyncCode\AutoControl\scripts\本地打包\0%%i" /E/Y/I
		) else (
			xcopy "E:\SyncCode\AutoControl\scripts\本地打包\001" "E:\SyncCode\AutoControl\scripts\本地打包\%%i" /E/Y/I
		)
	)
)
goto aa)
echo "太小!"

:aa
pause
exit 
  1. 复制文件
@echo off
setlocal enabledelayedexpansion

set /a ik=0
for /F "delims=" %%i in ('dir /s /b .\icon\*.png') do ( 
	set /a ik+=1
	echo "!ik!--------"
	echo %%i
	if !ik! LSS 10 (
		copy "%%i" "E:\SyncCode\AutoControl\scripts\本地打包\00!ik!\res\logo.png" /y
		copy "%%i" "E:\SyncCode\AutoControl\scripts\本地打包\logo\00!ik!.png" /y
	) else (
		if !ik! LSS 100 (
			copy "%%i" "E:\SyncCode\AutoControl\scripts\本地打包\0!ik!\res\logo.png" /y
			copy "%%i" "E:\SyncCode\AutoControl\scripts\本地打包\logo\0!ik!.png" /y
		) else (
			::mkdir "E:\SyncCode\AutoControl\scripts\本地打包\lsc\!ik!"
			copy "%%i" "E:\SyncCode\AutoControl\scripts\本地打包\!ik!\res\logo.png" /y
			copy "%%i" "E:\SyncCode\AutoControl\scripts\本地打包\logo\!ik!.png" /y
		)
	)
	
)

这里注意循环递增需添加

setlocal enabledelayedexpansion
才可以使用 !count! 方式的实时变量

  1. nodejs替换字符
var fs = require("fs");
var path=require('path');
const { v4: uuidv4 } = require('uuid');
const { transliterate , slugify } = require('transliteration');

function ConvertToTable(data, callBack) {
    data = data.toString();
    var table = new Array();
    var rows = new Array();
    rows = data.split("\r\n");
    for (var i = 0; i < rows.length; i++) {
        table.push(rows[i].split(","));
    }
    callBack(table);
}

function modifyDir( index ,  lineData ){

  var _i = index<10 ? "00"+index : ( index<100 ? "0"+index : index );

  var filePath=path.resolve(__dirname+'\\'+_i+'\\');
  //readdir方法读取文件名
  //readFile方法读取文件内容
  //writeFile改写文件内容
  console.log(filePath);
  fs.readdir(filePath, { encoding:'utf8',withFileTypes:true }, function (err,data) {
    if(err){console.log(err);return;}
    data.forEach(function(item, index) {

      var currentItemPath = filePath+"\\"+item.name;
      console.log(currentItemPath)
        if(item.isDirectory()){return false;}

      fs.readFile(currentItemPath,'utf8',function(err,files){
        result = result.replace(/com.xxxx/g, "com."+slugify(lineData[0]).replace(/\-/g ,"")+"."+slugify(lineData[0]).replace(/\-/g ,"") );
        result = result.replace(/bcdsasas/g, uuidv4().replace(/\-/g ,""));

        fs.writeFile(currentItemPath, result, 'utf8', function (err) {
           if (err) return console.log(err);
        });

      })
    });

  });
}


fs.readFile('apkinfo2.csv', 'utf8', function (err, data) {
    var table = new Array();
    if (err) {
        console.log(err.stack);
        return;
    }
    ConvertToTable(data, function (table) {
        console.log(table);
        for (var i in table) {
          modifyDir( parseInt(i)+1,table[i]);
        }
    })
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值