Friday, September 6, 2013

How to rename file with first 32 characters of text file with batch file

How to rename file with first 32 characters of text file with batch file

I would please like someone to help me with this code (shown below). All i
want is the new file name needs to be the first 32 characters of the first
line of the file?
cd c:\test2\test
for /f "delims=" %%i in ('dir /a-d /b *.txt') do (
set nname=
set fname=%%i
for /f "usebackq delims=" %%f in ("%%i") do if not defined nname set
"nname=%%f"
setlocal enabledelayedexpansion
set "nname=!nname:~0,40!"
rename "!fname!" "!nname!"
endlocal
)
Thanks in advance...

No comments:

Post a Comment