Renaming files from txt within file

May 27, 2009 at 03:22:51
Specs: Windows XP
Please help!
I want to rename hundreds of files from my local directory by getting a string of text from the file.
For example: Filename: tsa012835182.txt
I want to rename it to include the text from within the file. The file contains several lines of text
15-05-09 003094 0610
15-05-09 003094 0715
15-05-09 003094 1715
15-05-09 003094 1807
I want to get 15-05-09 the first line in column 1, and then rename it as the name of the file.
The final filename should look like: TSA01-14-05-09.txt
Then proceed with the next file.
The 15-05-09 text is different in each file but in same location (column 1).

The final filename for this one should look like: tsa0115-05-09.txt

See More: Renaming files from txt within file

Report •

May 27, 2009 at 04:38:15
if you have Python on windows
import glob,os
for files in glob.glob("tsa*txt"):
    except Exception,e:
        print e
        filename = f.readline().strip().split()[0]
        newfilename = files[:5]+filename+".txt"
        except Exception,e:
            print e

save the above as and on command line
c:\test> python

Report •

May 27, 2009 at 04:54:58
Sorry I don't have python installed.

I have tried to run a script which was there for a similar requirement on the forum, but could not getthe same.

The difference being, my txt file is tab delimited and the file has to be named useing the 1 column and not the 4th and the 5th.

Report •

Related Solutions

Ask Question