在Windows批处理文件定期防爆pression [英] Regular Expression in a Windows Batch File

查看:255
本文介绍了在Windows批处理文件定期防爆pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找的方式与批处理作业重命名多个文件。
是的,我知道有很多围绕着可以实现这个应用程序。
但我需要一个自动化的方法,像一个批处理文件,我可以从调度器(SOS作业调度程序)调用。我们每天需要重命名数百个文件!

的目标是在文件的开头设置17-25 charcaters


  • 00010028229720270014468393_TB-E.pdf - > 00144683930001002822972027_TB-E.pdf

  • 000100282297202700144683931ESR-AF.pdf - > 001446839300010028229720271ESR-AF.pdf

  • 00010031141040250016353371ESR-AF.pdf - > 00163533700010031141040251ESR-AF.pdf

  • 0001003167580004001667217KTO.pdf - > 0016672170001003167580004KTO.pdf

下面的例子是比较清晰的:

0001 002822972 027 001446839 _TB-E .PDF - > 001446839 0001 002822972 027 _TB-E的.pdf


解决方案

@ECHO OFF
SETLOCAL
SETsourcedir = C:\\ sourcedir
FOR / Fdelims =%%一个IN(
 DIR / B / A-D%sourcedir%\\ *'
 )DO(
 SETNAME = %%一个
 CALL:变换
)GOTO:EOF:转变
ECHO仁%sourcedir%\\%名称%%名称:〜16,9 %%的名字:0,16〜%%名〜25%。
GOTO:EOF

所需的任命令仅仅是为了测试目的 ECHO 编辑。您确认后,该命令是正确的,将 ECHO REN REN 实际重命名文件。

注意,第一个例子中,你已经presented有39 ... 3 _TB-E ...在转换后的版本,即 3 缺失。

I'm looking for way to rename multiple files with a batch job. Yes, I know there are many Applications around which can achieve this. But I need an automated way, something like a Batch File which I can call from a Scheduler (SOS Job Scheduler). We need to rename hundreds of files daily!

The Goal is to set the 17-25 charcaters at the beginning of the file.

  • 00010028229720270014468393_TB-E.pdf -> 00144683930001002822972027_TB-E.pdf
  • 000100282297202700144683931ESR-AF.pdf -> 001446839300010028229720271ESR-AF.pdf
  • 00010031141040250016353371ESR-AF.pdf -> 00163533700010031141040251ESR-AF.pdf
  • 0001003167580004001667217KTO.pdf -> 0016672170001003167580004KTO.pdf

Here an example which is more clearer:

0001 002822972 027 001446839 _TB-E .pdf -> 001446839 0001 002822972 027 _TB-E .pdf

解决方案

@ECHO OFF
SETLOCAL
SET "sourcedir=c:\sourcedir"
FOR /f "delims=" %%a IN (
 'dir /b /a-d "%sourcedir%\*" '
 ) DO (
 SET "name=%%a"
 CALL :transform
)

GOTO :EOF

:transform
ECHO REN "%sourcedir%\%name%" "%name:~16,9%%name:~0,16%%name:~25%"
GOTO :eof

The required REN commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO REN to REN to actually rename the files.

Note that the very first example you've presented has ...393_TB-E... in the transformed version, that 3 is missing.

这篇关于在Windows批处理文件定期防爆pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆