Best method: string found?

Discuss RoboTask here
Post Reply
Rukbunker
Posts: 194
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Best method: string found?

Post by Rukbunker »

Hey Oleg,

We are checking a XML file with a certain filepath in it's content, for example \\hostname\v6b\gxf\221107A_Brandweerkazerne.mxf

Sometimes the file in the path doesn't exist, then we need to change the path in that XML and rewrite the XML again.
If the filepath containts v6a and the file doesn't exists there, the filepath should be v6b.
If the filepath containts v6b and the file doesn't exists there, the filepath should be v6a.

Everything works as it should but I think a bit cumbersome from my side, especially with part of swapping v6a to v6b and vice-versa. Ofcourse, I have used STR Replace and works. But I'm looking for a method like "Is string v6a initially found? Then replace to v6b" / "Is string v6b initially found? Then replace to v6a".

What is in your opinion, the most efficient way to achive this? Regex?
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Best method: string found?

Post by Oleg »

Do you want to check for the existence of a file and make changes in XML file if necessary?
Did I understand your purpose correctly?

If yes then regular expression is better. Look at RegExp Replace action
Oleg Yershov
Rukbunker
Posts: 194
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: Best method: string found?

Post by Rukbunker »

We get a XML like this:
<?xml version="1.0" encoding="utf-8" ?>
<JobSummary>
<SourceFileName>221107A_Brandweerkazerne.mxf</SourceFileName>
<SourceFilePath>\\hostname\v6b\gxf</SourceFilePath>

<Encoder>MP4</Encoder>
<TargetFileName>230711_brandweerkazerne_coa.mxf</TargetFileName>
<TargetFilePath>"\\hostname\v6b\geknipt"</TargetFilePath>
<Priority>1</Priority>
<TimecodeMarkIn>00:00:00:00</TimecodeMarkIn>
<TimecodeMarkOut>00:05:44:24</TimecodeMarkOut>
</JobSummary>
We rip out (and combine) the SourceFilePath+SourceFilename. That string, which represents a file (which is in this case \\hostname\v6b\gxf\221107A_Brandweerkazerne.mxf) will be checked for existance. If yes, tasks stops, everything is OK.

But, IF the XML contained v6b at first (like above) and the file does NOT exists, we should replace v6b by v6a and do the same check. Does the file exists than? Rewrite XML with v6a in the path.

But, IF the XML contained v6a at first and the file does NOT exists, we should replace v6a by v6b and do the same check. Does the file exists than? Rewrite XML with v6b in the path.

Replacing the XML with the correct path is not the issue, that's easy. It's more how to determine efficiently if v6a or v6b is used in the initial read of the XML.
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Best method: string found?

Post by Oleg »

Look at my example
I hope this is what you need

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1040"
Hide=INTEGER|0
ID=INTEGER|216880864
LogOnAsUser=INTEGER|1
Name=STRING|"Correct XML"
OnErrorTaskID=INTEGER|1879502808
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action15=FOLDER
Action16=FOLDER
Action17=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""sourceXML"" with value ""<?xml version=""1.0"" encoding=""utf-8"" ?>"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"sourceXML"
expand=STRING|"0"
linecount=STRING|"11"
varname=STRING|"sourceXML"
varvalue=STRING|"<?xml version=""1.0"" encoding=""utf-8"" ?>"
varvalue00000001=STRING|"<JobSummary>"
varvalue00000002=STRING|"<SourceFileName>221107A_Brandweerkazerne.mxf</SourceFileName>"
varvalue00000003=STRING|"<SourceFilePath>\\hostname\v6b\gxf</SourceFilePath>"
varvalue00000004=STRING|"<Encoder>MP4</Encoder>"
varvalue00000005=STRING|"<TargetFileName>230711_brandweerkazerne_coa.mxf</TargetFileName>"
varvalue00000006=STRING|"<TargetFilePath>""\\hostname\v6b\geknipt""</TargetFilePath>"
varvalue00000007=STRING|"<Priority>1</Priority>"
varvalue00000008=STRING|"<TimecodeMarkIn>00:00:00:00</TimecodeMarkIn>"
varvalue00000009=STRING|"<TimecodeMarkOut>00:05:44:24</TimecodeMarkOut>"
varvalue0000000A=STRING|"</JobSummary>"

[Actions\Action10]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//change a->b"
Params=FOLDER

[Actions\Action10\Params]
comment=STRING|"change a->b"

[Actions\Action11]
ActionID=STRING|"A_REGEXP_REPLACE"
Enabled=INTEGER|-1
Name=STRING|"RegExp Replace"
Params=FOLDER

[Actions\Action11\Params]
_rt_variables_produced=STRING|"NewXML"
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{sourceXML}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"(?i)<SourceFilePath>(.+)\\v6a\\(.+)</SourceFilePath>"
replacementcount=STRING|"0"
replacemode=STRING|"0"
repline00000000=STRING|"<SourceFilePath>$1\\v6b\\$2</SourceFilePath>"
replinecount=STRING|"1"
singleline=STRING|"0"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"NewXML"

[Actions\Action12]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else //contains ""b"""

[Actions\Action13]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//change b->a"
Params=FOLDER

[Actions\Action13\Params]
comment=STRING|"change b->a"

[Actions\Action14]
ActionID=STRING|"A_REGEXP_REPLACE"
Enabled=INTEGER|-1
Name=STRING|"RegExp Replace"
Params=FOLDER

[Actions\Action14\Params]
_rt_variables_produced=STRING|"NewXML"
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{sourceXML}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"(?i)<SourceFilePath>(.+)\\v6b\\(.+)</SourceFilePath>"
replacementcount=STRING|"0"
replacemode=STRING|"0"
repline00000000=STRING|"<SourceFilePath>$1\\v6a\\$2</SourceFilePath>"
replinecount=STRING|"1"
singleline=STRING|"0"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"NewXML"

[Actions\Action15]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action16]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action17]
ActionID=STRING|"A_DIALOG_SHOWTEXT"
Enabled=INTEGER|-1
Name=STRING|"Show Text"
Params=FOLDER

[Actions\Action17\Params]
autoclose=STRING|"0"
fromfile=STRING|"1"
line00000000=STRING|"Source XML:"
line00000001=STRING|"{sourceXML}"
line00000003=STRING|"Target XML:"
line00000004=STRING|"{NewXML}"
linecount=STRING|"5"
timeout=STRING|"10"

[Actions\Action2]
ActionID=STRING|"A_XML_GETNODE"
Enabled=INTEGER|-1
Name=STRING|"XML Get Single Node"
Params=FOLDER

[Actions\Action2\Params]
_rt_variables_produced=STRING|"s_path"
attcount=STRING|"0"
foundresult=STRING|"1"
loadfile=STRING|"0"
ordernum=STRING|"0"
path=STRING|"\*\SourceFilePath"
raiseerror=STRING|"1"
savechildcount=STRING|"0"
savedepth=STRING|"0"
savenodename=STRING|"0"
savepath=STRING|"0"
savetext=STRING|"1"
savexml=STRING|"0"
textvar=STRING|"s_path"
xml00000000=STRING|"{sourceXML}"
xmlcount=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_XML_GETNODE"
Enabled=INTEGER|-1
Name=STRING|"XML Get Single Node"
Params=FOLDER

[Actions\Action3\Params]
_rt_variables_produced=STRING|"s_filename"
attcount=STRING|"0"
foundresult=STRING|"1"
loadfile=STRING|"0"
ordernum=STRING|"0"
path=STRING|"\*\SourceFileName"
raiseerror=STRING|"1"
savechildcount=STRING|"0"
savedepth=STRING|"0"
savenodename=STRING|"0"
savepath=STRING|"0"
savetext=STRING|"1"
savexml=STRING|"0"
textvar=STRING|"s_filename"
xml00000000=STRING|"{sourceXML}"
xmlcount=STRING|"1"

[Actions\Action4]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action4\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{FileExists({s_path}\{s_filename})}"

[Actions\Action5]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action5\Params]
message=STRING|"File exists. Finish the task."
type=STRING|"3"

[Actions\Action6]
ActionID=STRING|"A_FLOW_EXIT"
Enabled=INTEGER|-1
Name=STRING|"Exit"
Params=FOLDER

[Actions\Action6\Params]
errorcode=STRING|"1"
mode=STRING|"0"

[Actions\Action7]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action8]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action8\Params]
message=STRING|"File des not exist."
type=STRING|"1"

[Actions\Action9]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then //contains ""a"""
Params=FOLDER

[Actions\Action9\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"6"
type=STRING|"0"
value1=STRING|"\v6a\"
value2=STRING|"{s_path}"

Oleg Yershov
Rukbunker
Posts: 194
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: Best method: string found?

Post by Rukbunker »

ALMOST what I had in mind ;) Thanks for your time!
Post Reply