batch to rename txt file using data inside

July 19, 2009 at 16:28:37
Specs: Windows XP
I need a specific batch to rename txt files to a
format, using the data from the txt file itself.

data within the files is for example:
0199999920090018888888888888P20

The file name has to get this name:
99999909.001

From the file character 3 till 8, 11 till 12, 13 till
15 is needed to create the new name.

Mark that after renaming, the txt extension
has to be gone. Also the dot is very important.

Can you help me?


See More: batch to rename txt file using data inside

Report •


#1
July 19, 2009 at 17:45:35
here's a vbscript

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file.txt"
Set objFile = objFS.GetFile(strFile)
strData = objFile.OpenAsTextStream.ReadAll
strNewName =  Mid(strData,3,5) & Mid(strData,11,2) & "." & Mid(strData,13,3)
objFile.Name = strNewName
set objFile = Nothing

GNU win32 packages | Gawk


Report •

#2
July 19, 2009 at 22:47:22
Thnx,

But I need to make it work for a bulk of several files. To make
it more difficult, some files don't have an extension.. What can
I do to make it work for more files, not with the name file.txt
(examples 9999992009001 is also a possibility) The files are
in one folder (can be the folder where the vbs is) and need to
be renamed all together.

Sorry for my english..


Report •

#3
July 19, 2009 at 23:26:24
try this
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
	Set objFile = objFS.GetFile(strFile)
	strData = objFile.OpenAsTextStream.ReadAll
	strNewName =  Mid(strData,3,5) & Mid(strData,11,2) & "." & Mid(strData,13,3)
	objFile.Name = strNewName
	Set objFile = Nothing	
Next

read up onvbscriptafter this.

GNU win32 packages | Gawk


Report •

Related Solutions


Ask Question