根据项目需求在同一个目录下的文件名替换 [英] Replace filename in same directory according to project requirement

查看:150
本文介绍了根据项目需求在同一个目录下的文件名替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4种类型的图形:图,表,公式和内联式

I have 4 types of graphics: figure, table, equation and inline equation.

有上述相同的目录中500个这样的图形。问题是,我想将其转换成喜欢这个项目要求:

There are above 500 such graphic in same directory. The problem is that I want to convert it into project requirement like this:

MUZ-171669-KH_eq_01.gif 必须转换为 muz123451669e001.gif

MUZ-171669-KH_eq_03a.gif 必须转换为 muz123451669e03a.gif

MUZ-171669-KH_fig_10.gif 必须转换为 muz1234516690010.gif

MUZ-171669-KH_fig_11a.gif 必须转换为 muz123451669011a.gif

MUZ-171669-KH_ineq_01.gif 必须转换为 muz123451669r001.gif

MUZ-171669-KH_ineq_04a.gif 必须转换为 muz123451669r04a.gif

MUZ-171669-KH_t_01.gif 必须转换为 muz123451669t001.gif

MUZ-171669-KH_t_02b.gif 必须转换为 muz123451669t02b.gif

这意味着:

preFIX MUZ 必须转换为 muz12345

Prefix MUZ must be converted to muz12345.

项目code号 171669 必须转换为 1669 。根据显卡系列一样的1669,1670,1671和这种变化等等,即 171670 必须转换为 1670

Project code number 171669 must be converted to 1669. This change according to graphics series like 1669, 1670, 1671 and so on, i.e. 171670 must be converted to 1670.

171671 必须转换为 1671 等。

现在四种后缀显卡名称:

Now four types of SUFFIX graphics name:

他们应该被永远转换为 4位只喜欢:

They should be always convert to 4 digit only like:

eq_01 必须转换为 E001

eq_03a 必须转换为 e03a

fig_10 必须转换为 0010

fig_11a 必须转换为 011A

ineq_01 必须转换为 R001

ineq_04a 必须转换为 r04a

t_01 必须转换为 T001

t_02b 必须转换为 t02b

有时 eq_03a,fig_11a,ineq_04a,t_02b 后缀发生。在这种情况下,他们应该被转换这样的 e03a,011A,r04a,t02b - 四位ONLY

Sometimes eq_03a, fig_11a, ineq_04a, t_02b suffix occur. In that case they should be converted like this e03a, 011a, r04a, t02b - FOUR DIGIT ONLY.

4的图形具有的 000 999 ,即 0001 0999 R001之间的文件数 R999 E001 E999 T001 T999

4 graphic have file number between 000 to 999, i.e. 0001 to 0999, r001 to r999, e001 to e999, t001 to t999.

我有以下code。但是,code未工作的身影和内嵌式图形。

I have the code below. But that code is not working for figure and inline equation graphics.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /f "tokens=1-7delims=-_." %%a IN ('dir /b /a-d "MUZ-*-*_*_*.gif" ') DO (
    IF "%%g"=="" (
        SET "num2=%%b"
        SET "fig=%%d"
        SET "num3=00%%e"
        REN "%%a-%%b-%%c_%%d_%%e.%%f" "muz12345!num2:~-4!!fig:~0,1!!num3:~-3!.%%f"
    )
)
GOTO :EOF

谁能帮助?

推荐答案

在与图像文件的目录中运行带有以下code的批处理文件:

Run a batch file with following code in the directory with the image files:

@echo off
setlocal EnableDelayedExpansion
for %%F in (MUZ-17????-KH_eq_??.*) do (
    set "OldFileName=%%~F"
    set "NewFileName=muz12345!OldFileName:~6,4!e0!OldFileName:~17,2!%%~xF"
    ren "!OldFileName!" "!NewFileName!"
)
for %%F in (MUZ-17????-KH_eq_???.*) do (
    set "OldFileName=%%~F"
    set "NewFileName=muz12345!OldFileName:~6,4!e!OldFileName:~17,3!%%~xF"
    ren "!OldFileName!" "!NewFileName!"
)
for %%F in (MUZ-17????-KH_fig_??.*) do (
    set "OldFileName=%%~F"
    set "NewFileName=muz12345!OldFileName:~6,4!00!OldFileName:~18,2!%%~xF"
    ren "!OldFileName!" "!NewFileName!"
)
for %%F in (MUZ-17????-KH_fig_???.*) do (
    set "OldFileName=%%~F"
    set "NewFileName=muz12345!OldFileName:~6,4!0!OldFileName:~18,3!%%~xF"
    ren "!OldFileName!" "!NewFileName!"
)
for %%F in (MUZ-17????-KH_ineq_??.*) do (
    set "OldFileName=%%~F"
    set "NewFileName=muz12345!OldFileName:~6,4!r0!OldFileName:~19,2!%%~xF"
    ren "!OldFileName!" "!NewFileName!"
)
for %%F in (MUZ-17????-KH_ineq_???.*) do (
    set "OldFileName=%%~F"
    set "NewFileName=muz12345!OldFileName:~6,4!r!OldFileName:~19,3!%%~xF"
    ren "!OldFileName!" "!NewFileName!"
)
for %%F in (MUZ-17????-KH_t_??.*) do (
    set "OldFileName=%%~F"
    set "NewFileName=muz12345!OldFileName:~6,4!t0!OldFileName:~16,2!%%~xF"
    ren "!OldFileName!" "!NewFileName!"
)
for %%F in (MUZ-17????-KH_t_???.*) do (
    set "OldFileName=%%~F"
    set "NewFileName=muz12345!OldFileName:~6,4!t!OldFileName:~16,3!%%~xF"
    ren "!OldFileName!" "!NewFileName!"
)
endlocal

这篇关于根据项目需求在同一个目录下的文件名替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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