Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
How can i automatically rename txts based on content?
I have tons of texts named as IM0102091618_1 for example,i open them and rename them as IM0102091618_1-2721 for example.I find the "2721" inside .txt
The txt inside looks like this :
092102721 2007823000314 ΚΑΠΡΙ ΚΛΑΣΙΚΟ ΕΙΣ. Black 42 1
092102721 2008823000311 ΚΑΠΡΙ ΚΛΑΣΙΚΟ ΕΙΣ. Black 44 1
092102721 2008823000311 ΚΑΠΡΙ ΚΛΑΣΙΚΟ ΕΙΣ. Black 44 1What i want is very simple,though i don't know how to achieve it...
All i want is to take the 5 to 9 digits from first line and rename after the txtAny options on how can i achive this please?
Thanks on first hand,any help would be much appreciated
PS. I have tried the program named as "Rename Text Files Based On Content Software" and it's not working...If anyone could make a .bat or something i would be more than grateful!

First of all move the files you want to rename into a new empty folder; then set the prompt to that folder as the current directory by issuing the CD command (type CD /? for help) and run the following batch. Move away the renamed files and repeat the process with a new batch of files to rename.
@echo off & setlocal EnableDelayedExpansion for %%j in (*.) do ( set /P name=< "%%j" set name=!name:~4,5! ren "%%j" !name!.txt ) :: End_Of_Batch
The above script assumes the files to be renamed have no extension at all as you posted in your example.

Hi.
I'm running Vista Buisness, and can't get it working.
Have 2000 txt-files with filename 001-002-003... and want to add the first line of text from file to filename.
Tried this (found here in forum):@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
for %%j in (*.txt) do (
set /P name=< "%%j"
echo %%name
echo ren "%%j" "%%j - !name!.txt"
)
pause
endlocalIt was supposed to take the first line of text and add (rename) the file with it. It works with the first file, but all following files get the SAME text added to filename (file-number is fine counting up > "001-first text" - "002-first text" - "003-first text" instead of "002-second text" - "003-third text"). So it don't loop the reading of the first line of txt - help !
Allso tried this with same error:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "delims=" %%a in ('dir *.txt /b/a-d') do (
set /p line=<%%~fa
for /f "delims=" %%b in ("!line!") do echo ren "%%~fa" "%%~fa - %%b.txt"
)
pause
endlocalThanks for your help !

Both those code scraps look like they lost something when they went through the blender.
Since this thread is about to go stale date, you ought to start a new one.
Be clear about what parts to use. The whole first LINE?
=====================================
If at first you don't succeed, you're about average.M2

Found that this actually worked - if the first line in NOT empty/blank:
@ECHO OFF
setlocal enabledelayedexpansion
for %%i in (*.txt) do (
set /P name=< "%%i"
echo ren "%%i" "%%i - !name!.txt"
)
endlocalIt renames the files with previous name + first text-line (song number + name).

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |