标题: 尺码转换 [打印本页]
作者: wojiaomt 时间: 2021-9-5 02:15 标题: 尺码转换
文件夹内有多个TXT文件(包含多级子文件夹),内容如下。 把cm换算成in 英寸 . 1厘米等于0.3937007874英寸. 结果取到小数点后1位。 直接在txt里替换。
有偿100
size:XS
Shoulder:41 cm
Bust:74 cm
Waist Size:60 cm
Hip Size:66 cm
Sleeve Length:58.5 cm
Length:92 cm
Cuff:15 cm
作者: newswan 时间: 2021-9-5 08:02
本帖最后由 newswan 于 2021-9-5 08:21 编辑
直接修改文件- @cd /d %~dp0 & powershell -command "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause & exit/b
-
- set $sour= "."
-
- Get-ChildItem -Path $sour -Filter "*.txt" -Recurse | foreach-object {
- write-host ("`n" + $_.fullname)
- get-content $_ | foreach-object {
- if ($_ -match "(.*:)(\d+(?:.\d)?) cm")
- {
- $inch = [Math]::Round(([double]$matches[2]) * 0.3937007874 , 1)
- ($matches[1] + $inch + " inch")
- }
- else
- {
- $_
- }
- } | out-file ($_.fullname)
- }
复制代码
作者: zaqmlp 时间: 2021-9-5 10:03
- /*&cls&echo off
- cd /d "%~dp0"
- dir /a-d-h/b/s *.txt|cscript -nologo -e:jscript "%~f0"
- pause
- exit
- */
- var fso=new ActiveXObject('Scripting.FileSystemObject');
- while(!WSH.StdIn.AtEndOfStream){
- var it=WSH.StdIn.ReadLine();
- WSH.echo(it);
- try{
- var file=fso.GetFile(it);
- var f1=fso.OpenTextFile(file.Path, 1);
- var text=f1.ReadAll();
- f1.Close();
- text=text.replace(/(\d+(?:\.\d+)?) cm/g,function(a,b){
- return (Number(b)*0.3937007874).toFixed(1).replace(/\.0$/,'')+' in';
- });
- var f2=fso.CreateTextFile(file.Path, 2);
- f2.Write(text);
- f2.Close();
- }catch(e){}
- }
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |