rename a file baesd in the 1 line of the file
Moderator: DosItHelp
rename a file baesd in the 1 line of the file
Hi,
I need to rename a file with the following format MYFILE_<DATE>_<ID>, where the DATE and ID are obtained based on the 1st line of the file, the DATE being 8 characters (in format YYYYMMDD) start in position 10 and the ID (the number of processing) in the 7 characters that begin in 21 position.
Can anyone help me with a script to rename the file in this way?
thanks in advance
I need to rename a file with the following format MYFILE_<DATE>_<ID>, where the DATE and ID are obtained based on the 1st line of the file, the DATE being 8 characters (in format YYYYMMDD) start in position 10 and the ID (the number of processing) in the 7 characters that begin in 21 position.
Can anyone help me with a script to rename the file in this way?
thanks in advance
Re: rename a file baesd in the 1 line of the file
So you want the files renamed, with the existing filenames and the date and ID added (from the first line as you mentioned).
Is that right?
Are the files text files? Or binary files?
Is that right?
Are the files text files? Or binary files?
Re: rename a file baesd in the 1 line of the file
File text
ex:
1H00 20120820 1234567
ex:
1H00 20120820 1234567
Re: rename a file baesd in the 1 line of the file
RMSoares wrote:File text
ex:
1H00 20120820 1234567
You sure this data isn't tab delimited. The positions are not matching up to what you described in your first post.
Re: rename a file baesd in the 1 line of the file
While you are answering Squashman, please answer my question too.
Re: rename a file baesd in the 1 line of the file
The text file must be rename, the file MYFILE.dat must be renamed to MYFILE_<DATE>_<ID>.dat
The text file is fixed delimited, in the example same sapces are missing
A new example, the file MYFILE.dat, with the first line :
1H0012345201208201231234567
must be rename to MYFILE_20120820_1234567.dat
The text file is fixed delimited, in the example same sapces are missing
A new example, the file MYFILE.dat, with the first line :
1H0012345201208201231234567
must be rename to MYFILE_20120820_1234567.dat
Re: rename a file baesd in the 1 line of the file
This works here:
ren "myfile.dat" "myfile_20120820_1234567.dat"
Code: Select all
@echo off
set /p "data="<"myfile.dat" >nul
ren "myfile.dat" "myfile_%data:~9,8%_%data:~20,7%.dat"
pause
ren "myfile.dat" "myfile_20120820_1234567.dat"
Re: rename a file baesd in the 1 line of the file
Hi,
a correction, the file that we will receive have in the first line will be:
1H001234520120820123123 XPTO
and must be rename to MYFILE_20120820_0000123.dat
The ID (the number of processing) correspondig to the 7 characters that begin in 21 position, must be format, removed the spaces in rigth and put '0' at left.
The value of ID ('123 ') must be convert to '0000123'
How can i do that ?
a correction, the file that we will receive have in the first line will be:
1H001234520120820123123 XPTO
and must be rename to MYFILE_20120820_0000123.dat
The ID (the number of processing) correspondig to the 7 characters that begin in 21 position, must be format, removed the spaces in rigth and put '0' at left.
The value of ID ('123 ') must be convert to '0000123'
How can i do that ?
Re: rename a file baesd in the 1 line of the file
Just for the record, it is bad form to change what you asked for after you have working code.
I don't follow what you are saying.
Give character positions and text as examples for what you want.
RMSoares wrote:The ID (the number of processing) correspondig to the 7 characters that begin in 21 position, must be format, removed the spaces in rigth and put '0' at left.
I don't follow what you are saying.
Give character positions and text as examples for what you want.
Re: rename a file baesd in the 1 line of the file
Yes, it's very bad to changed the rules of the game when we are finishing
My file will have this 1º record
1H001234520120820123 XPTO
Base ond the 1º record i will renamed the file to MYFILE_<DATE>_<ID>
Where DATE will be the 8 position from 10 and ID (the number of processing) in the 7 characters that begin in 21 position.
In the case of ID i will get '123 ' (123 more four spaces) and in the name of the file it will be foamted to '0000123', align to rigth and put zeros at left.
DATE=20120820
ID=0000123
And name of the file will be: MYFILE_20120820_0000123.dat
My file will have this 1º record
1H001234520120820123 XPTO
Base ond the 1º record i will renamed the file to MYFILE_<DATE>_<ID>
Where DATE will be the 8 position from 10 and ID (the number of processing) in the 7 characters that begin in 21 position.
In the case of ID i will get '123 ' (123 more four spaces) and in the name of the file it will be foamted to '0000123', align to rigth and put zeros at left.
DATE=20120820
ID=0000123
And name of the file will be: MYFILE_20120820_0000123.dat
Re: rename a file baesd in the 1 line of the file
RMSoares wrote:My file will have this 1º record
1H001234520120820123 XPTO
Base ond the 1º record i will renamed the file to MYFILE_<DATE>_<ID>
Where DATE will be the 8 position from 10 and ID (the number of processing) in the 7 characters that begin in 21 position.
Can you show me the 7 characters that begin in 21 position?
Re: rename a file baesd in the 1 line of the file
Big mistake, the correct record is
1H001234520120820XXX123 XPTO
where DATE=20120820
ID="123 " (without quotes)
1H001234520120820XXX123 XPTO
where DATE=20120820
ID="123 " (without quotes)