Renaming a file

 SenHu -

i am trying to rename a file (version.txt) using a batch command but I need the file name to be part of the data that is written within the version.txt file

for example:
within the version.txt file, there is data on a line such as the following

GCA.atmID = 12345678

the 12345678 will always be 8 alpha-numeric characters, but will be different for each file. I would like to extract/parse the eight characters after the space after the equal sign and rename the version.txt to 12345678.txt.

I appreciate in advance any assistance.

2 replies

Registration date
Friday May 22, 2009
Last seen
February 2, 2010
Hello tk:

Rather simple. You can do it with biterscripting ( ) . Here is the small script to rename version.txt. (I have added comments so you can edit the script if necessary.)

# Go to directory where version.txt is stored.
ccd "some directory"     # Enter correct folder path here.

# Read version.txt into a variable.
var str content ; cat "version.txt" > $content

# Remove everything upto "GCA.atmID = ".
stex "^GCA.atmID = ^]" $content > null

# The next 8 characters are the new file name.
var str newname ; chex "8]" $content > $newname

# Rename file to $newname.txt.
system rename "version.txt" ($newname+".txt")

Email me if you need more help. Don't forget to mark this thread as resolved if you find this answer useful.

Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2821 users have said thank you to us this month


now I have a file name that I need to make a part of the text file. I have 255 text files with information that is formatted similarly. The text file has information related to a unit. The unit id is the file name. I would like to be able to take the file name and make it the first line of the text file. thanks in advance for your assistance!
When using the following commands in biterscripting, they need to be preceeded by system.


For example:

system copy "X.txt" "Y.txt"

The above will copy file X.txt to Y.txt.

system delete "X.txt"

The above will delete file X.txt.


Also, it is always best to use double quotes around file names and paths with the system command.