Computing.Net > Forums > Programming > batch to rename txt file using data inside

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch to rename txt file using data inside

Reply to Message Icon

Name: paultje100
Date: July 19, 2009 at 16:28:37 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: July 19, 2009 at 17:45:35 Pacific
Reply:

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


0

Response Number 2
Name: paultje100
Date: July 19, 2009 at 22:47:22 Pacific
Reply:

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..


0

Response Number 3
Name: ghostdog
Date: July 19, 2009 at 23:26:24 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch to rename txt file using data inside

Using Batch to Rename 'some' files www.computing.net/answers/programming/using-batch-to-rename-some-files/15862.html

Rename *.TXT file with 24 Hour Time Stamp www.computing.net/answers/programming/rename-txt-file-with-24-hour-time-stamp/19772.html

Extract an excel page to a txt file www.computing.net/answers/programming/extract-an-excel-page-to-a-txt-file/17053.html