I have a file of this genre:
blabla_(29ago2017)_blabla
I need you to look like this:
(29ago2017)
There is some code in .bat that will make this work for me, ie just leave what is in parentheses as the filename.
I have a file of this genre:
blabla_(29ago2017)_blabla
I need you to look like this:
(29ago2017)
There is some code in .bat that will make this work for me, ie just leave what is in parentheses as the filename.
Replace .txt with the correct extension of your files.
for %%f in (*_*_*.txt) do @(
for /F "usebackq tokens=2,4 delims=_." %%p in ('%%f') do @(
ren %%f %%p.%%q
)
)
If the files do not have an extension, then:
for %%f in (*_*_*) do @(
for /F "usebackq tokens=2 delims=_." %%p in ('%%f') do @(
ren %%f %%p
)
)
Just run the Script in the folder where the files are
@echo off
REM ----------------------------POR: CRISTIAN MOTA-----------------------------
setlocal enabledelayedexpansion
mode 40,10
title ~ RENOMEADOR DE FICHEIROS
set line=0
echo.>%tmp%\nomes.txt
dir /b *.txt | findstr /v "nomes.txt">>%tmp%\nomes.txt
echo.fim_arq.txt>>%tmp%\nomes.txt
type "%tmp%\nomes.txt" | find /v /c "">%tmp%\quant_fich.txt
set /p quant=<%tmp%\quant_fich.txt
set /a quant=%quant%-2
:main
set /a line=%line%+1
for /f "skip=%line% tokens=* delims=(" %%R in (%tmp%\nomes.txt) do (set fich=%%R
if "!fich!" equ "fim_arq.txt" (ren "*.txt" "(*).txt"
setlocal disabledelayedexpansion
echo.
echo.
if "%quant%" equ "1" (echo. %quant% ficheiro foi renomeado !) else (echo. %quant% ficheiros foram renomeados !)
echo.
echo. FIM DA INSTRUۂO ! &pause >nul
exit)
set num=0
set ch=%%R
:loop1
if "!ch:~%num%,1!" neq "(" (set /a num=%num%+1 & goto loop1) Else (set ch=!ch:~%num%!
ren "!fich!" "!ch!"
goto main
)
)