reading info from a file name

Discuss RoboTask here

reading info from a file name

Postby benny.davidovich » Tue May 19, 2020 10:25 am

Hello,

I have pdf files that have some info that i want to get from them, the info location is between the first left char and until the first space.
file name expample:
40377 xxx yyy n 98.pdf i want to get the 40377
11 dfdf er 44.pdf i want to get the 11
0001244 frtr dd.pdf i want to get 0001244

what is the correct function for do it?

Thanks
Benny
benny.davidovich
 
Posts: 2
Joined: Wed Oct 30, 2019 1:21 pm

Re: reading info from a file name

Postby Oleg » Tue May 19, 2020 1:46 pm

Look at my small example below
You can determine position of 1-s space and extract sub-string before this position.
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
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
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task212"
Hide=INTEGER|0
ID=INTEGER|-1441412904
LogOnAsUser=INTEGER|1
Name=STRING|"get 1-st number from the name"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action1\Params]
destvar=STRING|"FILENAME"
line0=STRING|"40377 xxx yyy n 98.pdf"
line1=STRING|"11 dfdf er 44.pdf"
line2=STRING|"0001244 frtr dd.pdf"
line3=STRING|"TheNameWithoutSpace.pdf"
linecount=STRING|"4"
sourcetext=STRING|"1"

[Actions\Action2]
ActionID=STRING|"A_STR_POS"
Enabled=INTEGER|-1
Name=STRING|"STR Pos"
Params=FOLDER

[Actions\Action2\Params]
case=STRING|"0"
from=STRING|"1"
search=STRING|"{Chr(32)}"
source=STRING|"{filename}"
variable=STRING|"p"

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

[Actions\Action3\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"1"
value1=STRING|"{p}"
value2=STRING|"0"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Name: {filename}"""
Params=FOLDER

[Actions\Action4\Params]
icon=STRING|"0"
msg0=STRING|"Name: {filename}"
msg2=STRING|"Spase is not found!"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"

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

[Actions\Action6]
ActionID=STRING|"A_STR_EXTRACT"
Enabled=INTEGER|-1
Name=STRING|"STR Extract"
Params=FOLDER

[Actions\Action6\Params]
amount=STRING|"{p}"
from=STRING|"1"
source=STRING|"{FileName}"
variable=STRING|"num"

[Actions\Action7]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Name: {filename}"""
Params=FOLDER

[Actions\Action7\Params]
icon=STRING|"1"
msg0=STRING|"Name: {filename}"
msg2=STRING|"extracted string: {num}"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"

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

[Actions\Action9]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

Oleg Yershov
Oleg
Site Admin
 
Posts: 2555
Joined: Thu Jan 01, 1970 1:00 am

Re: reading info from a file name

Postby benny.davidovich » Wed May 20, 2020 8:15 am

Thanks Oleg,

Now i have some other problem, sometime the numbers are at the beginning and some time at the end, for example:
40377 06.1.28 petter maxim
peter maxim 06.1.28 40377

and if it possible to take only numbers and not other char?

Thanks
benny.davidovich
 
Posts: 2
Joined: Wed Oct 30, 2019 1:21 pm

Re: reading info from a file name

Postby Rukbunker » Wed May 20, 2020 10:21 am

Using version 7.6.0.984
Rukbunker
 
Posts: 124
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: reading info from a file name

Postby Oleg » Wed May 20, 2020 11:00 am

benny.davidovich wrote: want to get from them, the info location is between the first left char and until the first space

Define task conditions more correctly, please.

Rukbunker wrote:It should be possible with Regex...

Yes, of course you have to use regular expressions in this case

Look at my example below, it works
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task220"
Hide=INTEGER|0
ID=INTEGER|-1803130410
LogOnAsUser=INTEGER|1
Name=STRING|"get the number from the file name"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action1\Params]
destvar=STRING|"FILENAME"
line0=STRING|"40377 xxx yyy n 98.pdf"
line1=STRING|"11 dfdf er 44.pdf"
line2=STRING|"0001244 frtr dd.pdf"
line3=STRING|"TheNameWithoutSpace.pdf"
line4=STRING|"40377 06.1.28 petter maxim.pdf"
line5=STRING|"peter maxim 06.1.28 40377.pdf"
line6=STRING|"peter maxim 40377 06.1.28.pdf"
linecount=STRING|"7"
sourcetext=STRING|"1"

[Actions\Action10]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Name: ""{filename}"""""
Params=FOLDER

[Actions\Action10\Params]
icon=STRING|"0"
msg0=STRING|"Name: ""{filename}"""
msg2=STRING|"expression is not found!!"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"

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

[Actions\Action12]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""NAME"" with value ""{ExtractFileNameNoExt({filename})}"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"1"
varname=STRING|"NAME"
varvalue=STRING|"{ExtractFileNameNoExt({filename})}"

[Actions\Action3]
ActionID=STRING|"A_REGEXP_MATCH"
Enabled=INTEGER|-1
Name=STRING|"RegExp Match"
Params=FOLDER

[Actions\Action3\Params]
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{name}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"^(\d+)\s|\s(\d+)\s|\s(\d+)$"
savesubexpression=STRING|"1"
singleline=STRING|"0"
subexpressionpos=STRING|"0"
subexpressionvar=STRING|"expr"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"found"

[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|"{found}"

[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""EXPR"" with value ""{expr(0)}"""
Params=FOLDER

[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"EXPR"
varvalue=STRING|"{expr(0)}"

[Actions\Action6]
ActionID=STRING|"A_REGEXP_MATCH"
Enabled=INTEGER|-1
Name=STRING|"RegExp Match"
Params=FOLDER

[Actions\Action6\Params]
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{expr}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"(\d+)"
savesubexpression=STRING|"1"
singleline=STRING|"0"
subexpressionpos=STRING|"0"
subexpressionvar=STRING|"expr"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"found"

[Actions\Action7]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""NUM"" with value ""{expr(1)}"""
Params=FOLDER

[Actions\Action7\Params]
expand=STRING|"1"
varname=STRING|"NUM"
varvalue=STRING|"{expr(1)}"

[Actions\Action8]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""File Name: {filename}"""
Params=FOLDER

[Actions\Action8\Params]
icon=STRING|"1"
msg0=STRING|"File Name: {filename}"
msg1=STRING|"Name only: {name}"
msg3=STRING|"extracted string: {num}"
msgcount=STRING|"4"
playsound=STRING|"0"
showmessage=STRING|"1"

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

Oleg Yershov
Oleg
Site Admin
 
Posts: 2555
Joined: Thu Jan 01, 1970 1:00 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 20 guests

cron