Solved Batch rename of multiple txt files from Line 27 of content.

February 1, 2013 at 02:01:47
Specs: Windows 7
Your site has been a big help for all of my batch files needs but i cannot find anything regarding the above subject. I have around 100 files in 1 folder that has a generic name and all has to be renamed according to its contents and can be found at line 27. I found the blow code but only gets from the first line;

@echo off
cls
setlocal enabledelayedexpansion

pushd g:\test\||echo Pushd failed - job terminated&& exit/b

for /f "tokens=*" %%1 in ('dir /b *.txt') do (
set /p inline=<%%1&set inline=!inline:~5,20!

echo %%1 will be renamed !inline!.txt
ren %%1 !inline!.txt

)

how can i modify this so that it will get it from line 27.

Thank you in advance.


See More: Batch rename of multiple txt files from Line 27 of content.

Report •


#1
February 1, 2013 at 03:39:17
✔ Best Answer
@echo off & setlocal
cls
pushd G:\test || (echo.Pushd failed - job terminated & exit/B)

for %%i in (*.txt) do call :REN %%i
ren *.tmp *.txt
exit /B

:REN
for /F "skip=26 tokens=*" %%j in ('type "%*"') do (set inline=%%j & goto :DONE)
:DONE
set inline=%inline:~5,20%
echo.%* will be renamed %inline%.txt
ren "%*" "%inline%.tmp"
exit /B


Report •

#2
February 1, 2013 at 06:11:11
Hey, great, works like a charm. Thank you very much for the fast reply IVO

Report •

Related Solutions


Ask Question