Board logo

标题: 【完结】20元求一个搜索命名的批处理 [打印本页]

作者: lxh623    时间: 2022-4-12 15:05     标题: 【完结】20元求一个搜索命名的批处理

本帖最后由 lxh623 于 2022-4-12 16:12 编辑

我有些数字命名的pdf,比如:14698469,想把它们按照文本a来改名字:
太时髦了!为什么不可以这样穿---(法)马克·博热著;(英)鲍勃·伦敦绘;刘宇彤译---台海出版社---2018---14698469
我的批处理是:
  1. @echo off
  2. for /f %%a in ('dir /s /b /a-d "J:\NDM\"') do (
  3.     for /f %%b in ('findstr "%%~nxa" a.txt') do (
  4.     ren "%%a" "%%b.pdf"
  5.     )
  6. )
  7. pause
复制代码
但是,试了一下,没有效果。电脑装了固态硬盘,开始不是本地磁盘,我自己重命名了磁盘。
谢谢!
作者: zaqmlp    时间: 2022-4-12 15:42

本帖最后由 zaqmlp 于 2022-4-12 16:03 编辑
  1. <# :
  2. cls&echo off&cd /d "%~dp0"&mode con lines=5000
  3. powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal \"%~f0\"|out-string|Invoke-Expression"
  4. pause
  5. exit
  6. #>
  7. $txtfile=".\a.txt";
  8. $folder="J:\NDM";
  9. if(-not (test-path -literal $txtfile)){write-host ('"'+$txtfile+'" not found');exit;}
  10. if(-not (test-path -literal $folder)){write-host ('"'+$folder+'" not found');exit;}
  11. $text=[IO.File]::ReadAllLines($txtfile, [Text.Encoding]::GetEncoding('GB2312'));
  12. $files=@(dir -literal $folder -recurse|?{($_.Name -match '^\d+\.pdf$') -and ($_ -is [System.IO.FileInfo])});
  13. for($i=0;$i -lt $files.length;$i++){
  14.     for($j=0;$j -lt $text.count;$j++){
  15.         if($text[$j].Contains($files[$i].BaseName)){
  16.             if($text[$j] -ne $files[$i].BaseName){
  17.                 $newname=($text[$j] -replace '[\t\\\/:\*\?"<>\|]','')+$files[$i].Extension;
  18.                 $newfile=$files[$i].Directory.FullName+'\'+$newname;
  19.                 write-host ($files[$i].FullName+' --> '+$newname);
  20.                 move-item -literal $files[$i].FullName $newfile -force -ErrorAction SilentlyContinue;
  21.                 break;
  22.             }
  23.         }
  24.     }
  25. }
复制代码

作者: lxh623    时间: 2022-4-12 15:54

zaqmlp 发表于 2022-4-12 15:42

谢谢!
除了数字,全部显示乱码。
̫ʱ���ˣ�Ϊʲô������������---��������ˡ�����������Ӣ���������׶ػ棻����ͮ��---̨��������---2018---14698469
作者: zaqmlp    时间: 2022-4-12 16:03

本帖最后由 zaqmlp 于 2022-4-12 16:05 编辑

回复 3# lxh623


   已修改
提需求最好同时打包部分原文件发网盘
作者: lxh623    时间: 2022-4-12 16:14

回复  lxh623


   已修改
提需求最好同时打包部分原文件发网盘
zaqmlp 发表于 2022-4-12 16:03

请查收。谢谢!




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2