Hello,
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.
Configuration: windows
Hello tk:
# 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. Sen
|
You are welcome.
#Script UpdateFiles.txt
var str list ; lf -rn "*.txt" "C:\somefolder" > $list
while ($list <> "")
do
# Get next file.
var str file ; lex "1" $list > $file
echo -e "Processing file " $file
# Get file contents into a string variable.
var str content ; cat $file > $content
# $file has full path. Get just the file name.
var str filename ; stex -p "^/^l[" $file > $filename
# Insert file name and "\n" before the first line.
lin "1" ($filename+"\n") $content > null
# Write updated content back to file
echo $content > { echo $file }
done
1. Save the above script as C:\UpdateFiles.txt. 2. Install biterscripting from http://www.biterscripting.com . 3. Start biterscripting. Run the above script by entering the following command. script "C:\UpdateFiles.txt" Please test the script before using. I have not been able to test it. Also, make sure you enter the correct folder name instead of C:\somefolder in the script. Please look at the file directory loop in biterscripting tutorial Section 4.1 at http://www.biterscripting.com/LearningScripting/Lesson4.html . Sen |
When using the following commands in biterscripting, they need to be preceeded by system.
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. etc. Also, it is always best to use double quotes around file names and paths with the system command. Sen |