Rename %filename% to an actual filename

March 26, 2010 at 03:14:38
Specs: Windows XP
I have been beating my brains out for the past few days and have tried many different variations of batch code to try to figure out how to take the text listed below, extract the work order codes (which can vary between 1 and 4 possible work orders with up to 6 numbers/letters), combine them along with a new time/date stamp that is generated then the code processes into a file name.

Date Message
06:00:56 03-26-2010 work order 123456
06:00:57 03-26-2010 work order 12345
06:00:58 03-26-2010 work order 1234
06:00:59 03-26-2010 work order 123

I will take this new file name and rename a certain log file.

I want the file name to look like this:

CEC WO 123456 12345 1234 123 100326_0615.txt

CEC = Machine
WO = Work Order
123456 = 1st work order
12345 = 2nd possible work order
1234 = 3rd possible work order
123 = 4th possible work order
100326 = 10 (year) 03 (month) 26 (date)
0615 = current time

Can someone point me in a right direction. I have read so many posts on here that my head is spinning.

Thanks,
Robert


See More: Rename %filename% to an actual filename

Report •


#1
March 26, 2010 at 04:26:16
Doesn't look that difficult ... but, how do you separate ? I mean, the above would result in the 1 line you need to name a file, but how does it go on ?

Like this :

Date Message
06:00:56 03-26-2010 work order 123456
06:00:57 03-26-2010 work order 12345
06:00:58 03-26-2010 work order 1234
06:00:59 03-26-2010 work order 123
10:55:56 03-26-2010 work order 4578
10:55:57 03-26-2010 work order 7858

??

Or does each set of max. 4 work orders, resides in max. 1 file only ?

How do you come to 06:15 ? I see only 06:00 ?!


Report •

#2
March 26, 2010 at 04:43:27
Doesn't look that difficult ... but, how do you separate ? I mean, the above would result in the 1 line you need to name a file, but how does it go on ?

-------------
The file is generated by an FTP server sent text file from a touchscreen. I did a copy and paste of the file. The fields are seperated by spaces. The date/time stamp from the text file is automatically generated at the time the event started. I am logging (in this case) 4 date/time stamped work order runs when they first begin. I know that I need to skip the first line "Date Message", find the 1st occurance of the word that is immediately after the first "work order", look and see if there are more work orders and capture those characters as well. 4 would be the maximum number of work orders that the system could generate. At the end of the machine cycle, a trend file is geneated that I will be tying this new file name header onto. This way the operator can look for a particular work order (up to 4), or a time / date, that has been saved in a folder. The application is a batch baking oven that runs heating ramp/soak profiles and the system generates a .txt file of the temperature/time/setpoint results. I am using Office Outlook to run a rule (start .exe file) when the system emails a profile complete message. I am converting the .bat file to .exe since Outlook doesn't run a .bat file.
---------------------

Like this :

Date Message
06:00:56 03-26-2010 work order 123456
06:00:57 03-26-2010 work order 12345
06:00:58 03-26-2010 work order 1234
06:00:59 03-26-2010 work order 123


??

Or does each set of max. 4 work orders, resides in max. 1 file only ?

How do you come to 06:15 ? I see only 06:00 ?!
----------------------
I want the date/time stamp to occur when the batch file runs at the end of the oven cycle. The 6:00 time stamp was just when the system actually generated a start time. I am looking to use the current date/time stamp to add to the file name for archiving purposes.

Thank you very much for such a prompt reply. I do a lot of PLC programming, and a "very little" bit of simple .bat type stuff. I have had portions of code to work but I'm sure there are much better ways that I can do.

Robert


Report •

#3
March 26, 2010 at 07:57:59
OK, I had a quick look, I dont have time at the moment, but this is the direction to go:

@echo off
setlocal enabledelayedexpansion

set all_order=

for /F "tokens=1,2,5" %%a in ('findstr /V "Date Message" test.txt') do (
echo %%a
echo %%b
echo %%c
set all_order=!all_order! %%c
)

echo all_order=%all_order%



Report •

Related Solutions

#4
March 26, 2010 at 07:59:23
Thank you. I will go through it now.

Have a great day.


Report •

#5
March 26, 2010 at 08:27:25
I substitued my message.txt for the test.txt. Message.txt is the message that I did the copy and paste from.


@echo off
setlocal enabledelayedexpansion

set all_order=

for /F "tokens=1,2,5" %%a in ('findstr /V "Date Message" message.txt) do (
echo %%a
echo %%b
echo %%c
set all_order=!all_order! %%c
)

echo all_order=%all_order%

Here is what I got on the screen:

[]D
ECHO is off
ECHO is off
all_order=

Am I missing something that I should already know?

Thanks,
Robert


Report •

#6
March 26, 2010 at 08:46:54
It would be expected behaviour when the file is not in the current directory, or when the file would not exist

Report •

#7
March 26, 2010 at 11:26:07
It was because of the unicode format that the text was in. I converted in to ansi and it does fine. One problem I have is that when I take the %all_order% result and try to add it to the file name, it will not let me becuase of the unused spaces in it. How can I substitute underscores for the spaces?


Thanks again,
Robert


Report •

#8
March 26, 2010 at 11:39:06
I figured it out.

echo %%a
echo %%b
echo %%c
set all_order=!all_order!_%%c <----added underscore after !
)

echo all_order=%all_order%

echo %all_order%
pause

Thanks,
Robert


Report •


Ask Question