我有一大批 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]
答案1
我怎样才能交换第一部分和结束部分?
例如(之前和之后):
[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