Txt renamer from content?

March 26, 2009 at 05:13:04
Specs: Windows XP
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 1

What 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 txt

Any 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!

See More: Txt renamer from content?

Report •

March 26, 2009 at 10:47:26
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.

Report •

June 1, 2009 at 18:15:13
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):

for %%j in (*.txt) do (
set /P name=< "%%j"
echo %%name
echo ren "%%j" "%%j - !name!.txt"

It 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:

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"

Thanks for your help !

Report •

June 2, 2009 at 02:35:59
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.


Report •

Related Solutions

June 3, 2009 at 00:58:56
Use replace pioneer....problem solved ;)

Report •

June 8, 2009 at 15:00:24
Found that this actually worked - if the first line in NOT empty/blank:

setlocal enabledelayedexpansion
for %%i in (*.txt) do (
set /P name=< "%%i"
echo ren "%%i" "%%i - !name!.txt"

It renames the files with previous name + first text-line (song number + name).

Report •

Ask Question