Alternando partes de um nome de arquivo

1

Eu tenho um grande lote de arquivos pdf que estão todos no formato "[algo] somethingelse".

Como posso mudar a primeira parte e a parte final para alcançar "somethingelse [something]"?

Por exemplo (antes e depois):

[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]
    
por Irregular User 02.10.2016 / 19:19

1 resposta

2

Como posso mudar a primeira parte e a parte final?

For example (before and after):

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

Use o seguinte arquivo de lote (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  

Notas:

  • Testado com os dois primeiros nomes de arquivos de exemplo em sua pergunta.

Exemplo de uso:

> 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

Leitura Adicional

por 02.10.2016 / 22:19