Search : in
By :

Renaming a file

Last answer on Jun 29, 2009 6:57:13 pm BST tk, on Jun 10, 2009 8:57:49 pm BST 
 Report this message to moderators

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

Best answers for « renaming a file » in :
Renaming multiple files in batch Show Renaming multiple files in batch Native features Using a third-party program Renaming a large number of files can quickly become tedious. Fortunately, there are tools to automate this task in many cases: Native features On Windows...
To see the content of a .jar file. ShowTo see the content of a .jar file. A simple method to see the content of a .jar file: firstly rename it in .zip file and open it. If you want to see the content of java programs compiled in .class, you must use a Java decompiler like...
VBA: How to know everything about the file folder ShowVBA: How to know everything about the file folder Preliminaries In module In sheet1 module Preliminaries Open a new workbook Add a module In module ' Declare variables for wizard. Public balloon1 As Balloon Public balloon2...
Delete a file locked in the memory ShowDelete a file locked in the memory You just download an object (file, folder or program) that makes your PC crash? Moreover, no anti-malware seems to solve this problem? Finally, it is impossible to move, rename and delete this...
Download Lupas Rename ShowLupas Rename is a program allowing to rename several files at the same time. The features of this software : - To rename files or directories - To ename files in récursive sub-directories - Shell integration (right button on a folder) - To...
Download Professional Renamer ShowAs its name suggests, this software is a program for renaming files and folders. All changes made to the file, appears immediately in the list of files, so you can see the result before confirming the move. Advantage It allows you to perform mass...
UNIX - Files ShowIntroduction to UNIX files In UNIX systems any element is represented in the form of a file. All files are architectured around a single tree structure where the base, called the root, is written "/". File types UNIX systems define different...
File sharing in Windows XP ShowAdvantages File sharing involves making the content of one or more directories available through the network. All Windows systems have standard devices making it easy to share the content of a directory. However, file sharing may lead to security...
Using FTP commands ShowThe FTP protocol FTP (File Transfer Protocol) is a protocol — meaning a standard language that lets two machines communicate — used so that computers of different types (or with different operating systems) can transfer files over a...

1

SenHu, on Jun 17, 2009 3:57:13 pm BST

Hello tk:

Rather simple. You can do it with biterscripting ( http://www.biterscripting.com ) . 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.

Sen

Reply to SenHu

2

tom k, on Jun 26, 2009 3:07:11 pm BST

Thx....

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!

Reply to tom k

3

SenHu, on Jun 29, 2009 6:51:33 pm BST

You are welcome.

If I understand the new task correctly, you have 255 .txt files, and you want to insert the name of the file as the first line of each file. That's also fairly simple with biterscripting ( http://www.biterscripting.com ) .

I will assume the .txt files are in C:\somefolder (and possibly subfolders). Here is the script.

#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

Reply to SenHu

4

 SenHu, on Jun 29, 2009 6:57:13 pm BST

When using the following commands in biterscripting, they need to be preceeded by system.

copy
rename
move
delete


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.

etc.

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

Sen

Reply to SenHu