.bat that deletes the file name leaving only what is inside ()

Asked

Viewed 107 times

0

I have a file like this:

blabla_(29ago2017)_blabla

I need you to stay like this:

(29ago2017)

Is there any code in . bat that does this job for me, ie just leave what is inside parentheses as file name.

2 answers

1

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 extension, then:

for %%f in (*_*_*) do @(
    for /F "usebackq tokens=2 delims=_." %%p in ('%%f') do @( 
        ren %%f %%p
    )
)

0

Just run 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
)
)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.