- 移动目录
@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
- 复制文件
@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! 方式的实时变量
- 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]);
}
})
});