切换文件名的一部分

不规则使用者

我有大量的pdf文件,它们的格式均为“ [something] somethingelse”。

如何在第一部分和最后部分之间切换以实现“ somethingelse [something]”?

例如(之前和之后):

[P. Morandi] Field and Galois Theory
Field and Galois Theory [P. Morandi]

[D. S. Bridges] Foundations of Real and Abstract Analysis
Foundations of Real and Abstract Analysis [D. S. Bridges] 

[J. G. Ratcliffe] Foundations of Hyperbolic Manifolds
Foundations of Hyperbolic Manifolds [J. G. Ratcliffe]

[R. E. Edwards] Fourier Series - A Modern Introduction Volume 1
Fourier Series - A Modern Introduction Volume 1 [R. E. Edwards]

[B. Bollobás] Graph Theory - An Introductory Course
Graph Theory - An Introductory Course [B. Bollobás]
戴维·波斯蒂尔

如何在第一部分和最后部分之间切换?

例如(之前和之后):

[P. Morandi] Field and Galois Theory.pdf
Field and Galois Theory [P. Morandi].pdf

使用以下批处理文件(test.cmd):

@echo off 
setlocal enabledelayedexpansion
for /f "usebackq delims=] tokens=1,2" %%a in (`dir /b *.pdf`) do (
  rem %%b is end part of name and will become 1st part
  rem remove extension
  set _first=%%~nb
  rem remove leading space
  set _first=!_first:~1!
  ren "%%a]%%b" "!_first! %%a].pdf"
  )
endlocal  

笔记:

  • 使用问题中的前两个示例文件名进行了测试。

用法示例:

> dir *.pdf
 Volume in drive F is Expansion
 Volume Serial Number is 3656-BB63

 Directory of F:\test

02/10/2016  19:43                 0 [D. S. Bridges] Foundations of Real and Abstract Analysis.pdf
02/10/2016  19:42                 0 [P. Morandi] Field and Galois Theory.pdf
               2 File(s)              0 bytes
               0 Dir(s)  1,733,769,015,296 bytes free

> test

> dir *.pdf
 Volume in drive F is Expansion
 Volume Serial Number is 3656-BB63

 Directory of F:\test

02/10/2016  19:42                 0 Field and Galois Theory [P. Morandi].pdf
02/10/2016  19:43                 0 Foundations of Real and Abstract Analysis [D. S. Bridges].pdf
               2 File(s)              0 bytes
               0 Dir(s)  1,733,769,015,296 bytes free

进一步阅读

  • Windows CMD命令行的AZ索引-Windows cmd行相关的所有内容的出色参考。
  • dir-显示文件和子文件夹的列表。
  • / f-针对另一个命令的结果循环命令。
  • 参数-命令行参数(或参数)是传递到批处理脚本中的任何值。
  • ren-重命名一个或多个文件。
  • 变量-提取变量的一部分(子字符串)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章