Read a Textfile , Append, Save Textfile

Discuss RoboTask here
Post Reply
gremlin
Posts: 35
Joined: Sun Jan 08, 2023 3:13 pm

Read a Textfile , Append, Save Textfile

Post by gremlin »

Hy,
I had a problem.
Robotask can´t Read / Write a Textfile.
Snipaste_2023-01-20_12-32-53.png
Snipaste_2023-01-20_12-32-53.png (10.22 KiB) Viewed 2197 times

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|0
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|1
Events=FOLDER
ExternalName=STRING|"Task4"
Hide=INTEGER|0
ID=INTEGER|736713264
LocalVariables=STRING|"DATEIUNDPFAD="
LogOnAsUser=INTEGER|1
Name=STRING|"Sander EP"
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

[Actions\Action1]
ActionID=STRING|"A_DIALOG_INPUTBOX"
Enabled=INTEGER|-1
Name=STRING|"Input Box"
Params=FOLDER

[Actions\Action1\Params]
password=STRING|"0"
prompt=STRING|"Länge"
stopifcancel=STRING|"0"
variable=STRING|"LAENGE"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_INPUTBOX"
Enabled=INTEGER|-1
Name=STRING|"Input Box"
Params=FOLDER

[Actions\Action2\Params]
password=STRING|"0"
prompt=STRING|"Breite"
stopifcancel=STRING|"0"
variable=STRING|"BREITE"

[Actions\Action3]
ActionID=STRING|"A_DIALOG_INPUTBOX"
Enabled=INTEGER|-1
Name=STRING|"Input Box"
Params=FOLDER

[Actions\Action3\Params]
password=STRING|"0"
prompt=STRING|"Höhe"
stopifcancel=STRING|"0"
variable=STRING|"HOEHE"

[Actions\Action4]
ActionID=STRING|"A_READ_TXTFILE"
Enabled=INTEGER|-1
Name=STRING|"Read Text File ""{DATEIUNDPFAD}"" (1252)"
Params=FOLDER

[Actions\Action4\Params]
codepage=STRING|"1252"
filename=STRING|"{DATEIUNDPFAD}"
replacenull=STRING|"0"
varname=STRING|"CSV"

[Actions\Action5]
ActionID=STRING|"A_STR_TRIM"
Enabled=INTEGER|-1
Name=STRING|"STR Trim"
Params=FOLDER

[Actions\Action5\Params]
custom=STRING|"0"
eol=STRING|"0"
lead=STRING|"1"
source=STRING|"CSV"
spaces=STRING|"1"
tabs=STRING|"1"
trailing=STRING|"1"
variable=STRING|"CSV"

[Actions\Action6]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set varible ""NEWFILENAME1"" with value ""C:\Temp\Dst\{ExtractFileNameNoExt({FileToProcess})}[{Year}-{MonthNo}-{Day}][{Hours}-{Minutes}-{Seconds}].{ExtractFileExt({FileToProcess})}"""
Params=FOLDER

[Actions\Action6\Params]
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"NEWFILENAME1"
varvalue=STRING|"c:\JTL-TMP\{Year}{MonthNo}{Day}{Time}{Seconds}.csv"

[Actions\Action7]
ActionID=STRING|"A_FILE_TEXTWRITE"
Enabled=INTEGER|-1
Name=STRING|"Create text file {NEWFILENAME1}"
Params=FOLDER

[Actions\Action7\Params]
encode=STRING|"0"
fileexists=STRING|"0"
filname=STRING|"{NEWFILENAME1}"
line0=STRING|"{CSV}{LAENGE};{BREITE};{HOEHE};;;;"
linecount=STRING|"1"
suppress=STRING|"0"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_FILE_MONITOR"
Name=STRING|"File Monitor"
Params=FOLDER
UniqueID=INTEGER|-263111290

[Events\Event1\Params]
chg=STRING|"0"
chga=STRING|"1"
chgsl=STRING|"1"
chgsm=STRING|"1"
chgtl=STRING|"1"
chgtm=STRING|"1"
del=STRING|"0"
folder1=STRING|"C:\JTL-TMP"
foldercount=STRING|"1"
incmask=STRING|"Sander-EP.csv"
interval=STRING|"10"
listmode=STRING|"1"
mon_files=STRING|"1"
mon_folders=STRING|"0"
new=STRING|"1"
newlistparameter=STRING|"DATEIUNDPFAD"
notsavestatus=STRING|"0"
onelistparameter=STRING|"DATEIUNDPFAD"
pass=STRING|"1"
passmode=STRING|"1"
required=STRING|"0"
saveresults=STRING|"0"
subfolders1=STRING|"0"

Maybe anyone can help me.
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Read a Textfile , Append, Save Textfile

Post by Oleg »

Could you send the file "Sander-EP.csv" for investigation to me to oleg(at)robotask.com
Probably your file contain some restricted symbols for code page 1252

Also try this task
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Also you can simply copy task text and paste it into the task list.
Do not forget to enable the task after importing.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|693415217
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|1
Events=FOLDER
ExternalName=STRING|"Task44"
Hide=INTEGER|0
ID=INTEGER|212909958
LocalVariables=STRING|"DATEIUNDPFAD="
LogOnAsUser=INTEGER|1
Name=STRING|"Sander EP (v2)"
OnErrorTaskID=INTEGER|1879502808
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

[Actions\Action1]
ActionID=STRING|"A_DIALOG_INPUTBOX"
Enabled=INTEGER|-1
Name=STRING|"Input Box"
Params=FOLDER

[Actions\Action1\Params]
password=STRING|"0"
prompt=STRING|"Länge"
stopifcancel=STRING|"0"
variable=STRING|"LAENGE"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_INPUTBOX"
Enabled=INTEGER|-1
Name=STRING|"Input Box"
Params=FOLDER

[Actions\Action2\Params]
password=STRING|"0"
prompt=STRING|"Breite"
stopifcancel=STRING|"0"
variable=STRING|"BREITE"

[Actions\Action3]
ActionID=STRING|"A_DIALOG_INPUTBOX"
Enabled=INTEGER|-1
Name=STRING|"Input Box"
Params=FOLDER

[Actions\Action3\Params]
password=STRING|"0"
prompt=STRING|"Höhe"
stopifcancel=STRING|"0"
variable=STRING|"HOEHE"

[Actions\Action4]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CSV"" with value ""{TextFile({DATEIUNDPFAD})}"""
Params=FOLDER

[Actions\Action4\Params]
expand=STRING|"1"
linecount=STRING|"1"
varname=STRING|"CSV"
varvalue=STRING|"{TextFile({DATEIUNDPFAD})}"

[Actions\Action5]
ActionID=STRING|"A_STR_TRIM"
Enabled=INTEGER|-1
Name=STRING|"STR Trim"
Params=FOLDER

[Actions\Action5\Params]
custom=STRING|"0"
eol=STRING|"0"
lead=STRING|"1"
source=STRING|"CSV"
spaces=STRING|"1"
tabs=STRING|"1"
trailing=STRING|"1"
variable=STRING|"CSV"

[Actions\Action6]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set varible ""NEWFILENAME1"" with value ""C:\Temp\Dst\{ExtractFileNameNoExt({FileToProcess})}[{Year}-{MonthNo}-{Day}][{Hours}-{Minutes}-{Seconds}].{ExtractFileExt({FileToProcess})}"""
Params=FOLDER

[Actions\Action6\Params]
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"NEWFILENAME1"
varvalue=STRING|"c:\JTL-TMP\{Year}{MonthNo}{Day}{Time}{Seconds}.csv"

[Actions\Action7]
ActionID=STRING|"A_FILE_TEXTWRITE"
Enabled=INTEGER|-1
Name=STRING|"Create text file {NEWFILENAME1}"
Params=FOLDER

[Actions\Action7\Params]
encode=STRING|"0"
fileexists=STRING|"0"
filname=STRING|"{NEWFILENAME1}"
line0=STRING|"{CSV}{LAENGE};{BREITE};{HOEHE};;;;"
linecount=STRING|"1"
suppress=STRING|"0"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_FILE_MONITOR"
Name=STRING|"File Monitor"
Params=FOLDER
UniqueID=INTEGER|2081193478

[Events\Event1\Params]
chg=STRING|"0"
chga=STRING|"1"
chgsl=STRING|"1"
chgsm=STRING|"1"
chgtl=STRING|"1"
chgtm=STRING|"1"
del=STRING|"0"
folder1=STRING|"C:\JTL-TMP"
foldercount=STRING|"1"
incmask=STRING|"Sander-EP.csv"
interval=STRING|"10"
listmode=STRING|"1"
mon_files=STRING|"1"
mon_folders=STRING|"0"
new=STRING|"1"
newlistparameter=STRING|"DATEIUNDPFAD"
notsavestatus=STRING|"0"
onelistparameter=STRING|"DATEIUNDPFAD"
pass=STRING|"1"
passmode=STRING|"1"
required=STRING|"0"
saveresults=STRING|"0"
subfolders1=STRING|"0"

Oleg Yershov
gremlin
Posts: 35
Joined: Sun Jan 08, 2023 3:13 pm

Re: Read a Textfile , Append, Save Textfile

Post by gremlin »

Hy,
thank you.
I had tried but at the CSV file no variable output , only the name of the variable ...
Snipaste_2023-01-23_12-20-59.png
Snipaste_2023-01-23_12-20-59.png (9.17 KiB) Viewed 2115 times
Also I must change the filename time with a : won´t write a filename ...

I had send you file via email

Thanks

Steven
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Read a Textfile , Append, Save Textfile

Post by Oleg »

":" is restricted symbol in file name.
Also you can not use several other symbols: *,?,\,/,",'
Oleg Yershov
gremlin
Posts: 35
Joined: Sun Jan 08, 2023 3:13 pm

Re: Read a Textfile , Append, Save Textfile

Post by gremlin »

Yes, I had solved this with the filename.
But at the outputfile there should be the variable {csv} string, not the name of the variable.
At the textfile 3 variables shows their value, but the {cvs} variable show only the text csv ???
Any idea ?

Thanks
Steven
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Read a Textfile , Append, Save Textfile

Post by Oleg »

but the {cvs} variable show only the text csv ???
Look at the step #5 (STR Trim)
you must use expression {csv} as source string (not CSV)

CSV is only CSV nothing more. But the expression {CSV} tells RoboTask that there is a variable name between braces and the task must try to extract the value.
Oleg Yershov
gremlin
Posts: 35
Joined: Sun Jan 08, 2023 3:13 pm

Re: Read a Textfile , Append, Save Textfile

Post by gremlin »

Hy,
yes I had tried this.
But when I use {csv} the output are this:
120;80;111;;;;
The three results are the values from the inputboxes.
But the string{cvs} should be before the result from inputbxes. but theres nothing ?

The Result should be: Robotask wait for a csv file. When exists ask for 3 Values. Add these to the end of the csv File and rename/move csv file.

Please can you help me to understand.
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Read a Textfile , Append, Save Textfile

Post by Oleg »

look at my next version below. It works.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|799397369
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|1
Events=FOLDER
ExternalName=STRING|"Task25"
Hide=INTEGER|0
ID=INTEGER|976207299
LogOnAsUser=INTEGER|1
Name=STRING|"Sander EP (v3)"
OnErrorTaskID=INTEGER|1879502808
Priority=INTEGER|3
RunOnClose=INTEGER|1
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_DIALOG_INPUTBOX"
Enabled=INTEGER|-1
Name=STRING|"Input Box"
Params=FOLDER

[Actions\Action1\Params]
password=STRING|"0"
prompt=STRING|"Länge"
stopifcancel=STRING|"0"
variable=STRING|"LAENGE"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_INPUTBOX"
Enabled=INTEGER|-1
Name=STRING|"Input Box"
Params=FOLDER

[Actions\Action2\Params]
password=STRING|"0"
prompt=STRING|"Breite"
stopifcancel=STRING|"0"
variable=STRING|"BREITE"

[Actions\Action3]
ActionID=STRING|"A_DIALOG_INPUTBOX"
Enabled=INTEGER|-1
Name=STRING|"Input Box"
Params=FOLDER

[Actions\Action3\Params]
password=STRING|"0"
prompt=STRING|"Höhe"
stopifcancel=STRING|"0"
variable=STRING|"HOEHE"

[Actions\Action4]
ActionID=STRING|"A_STR_TRIM"
Enabled=INTEGER|-1
Name=STRING|"STR Trim"
Params=FOLDER

[Actions\Action4\Params]
custom=STRING|"0"
eol=STRING|"1"
lead=STRING|"1"
source=STRING|"{DATEIUNDPFAD}"
spaces=STRING|"0"
tabs=STRING|"0"
trailing=STRING|"1"
variable=STRING|"DATEIUNDPFAD"

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

[Actions\Action5\Params]
expand=STRING|"1"
linecount=STRING|"1"
varname=STRING|"CSV"
varvalue=STRING|"{TextFile({DATEIUNDPFAD})}"

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

[Actions\Action6\Params]
custom=STRING|"0"
eol=STRING|"1"
lead=STRING|"1"
source=STRING|"{CSV}"
spaces=STRING|"1"
tabs=STRING|"1"
trailing=STRING|"1"
variable=STRING|"CSV"

[Actions\Action7]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|0
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action7\Params]
message=STRING|"{csv}"
type=STRING|"3"

[Actions\Action8]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""NEWFILENAME1"" with value ""c:\JTL-TMP\{DateTimeToFormat({DateTime},yyyy-mm-dd-hh-nn-ss)}.csv"""
Params=FOLDER

[Actions\Action8\Params]
expand=STRING|"1"
linecount=STRING|"1"
varname=STRING|"NEWFILENAME1"
varvalue=STRING|"c:\JTL-TMP\{DateTimeToFormat({DateTime},yyyy-mm-dd-hh-nn-ss)}.csv"

[Actions\Action9]
ActionID=STRING|"A_FILE_TEXTWRITE"
Enabled=INTEGER|-1
Name=STRING|"Create text file {NEWFILENAME1}"
Params=FOLDER

[Actions\Action9\Params]
encode=STRING|"0"
fileexists=STRING|"0"
filname=STRING|"{NEWFILENAME1}"
line0=STRING|"{CSV}"
line1=STRING|"{LAENGE};{BREITE};{HOEHE};;;;"
linecount=STRING|"2"
suppress=STRING|"1"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_FILE_MONITOR"
Name=STRING|"File Monitor"
Params=FOLDER
UniqueID=INTEGER|-529654911

[Events\Event1\Params]
chg=STRING|"1"
chga=STRING|"1"
chgsl=STRING|"1"
chgsm=STRING|"1"
chgtl=STRING|"1"
chgtm=STRING|"1"
del=STRING|"0"
folder1=STRING|"C:\JTL-TMP"
foldercount=STRING|"1"
incmask=STRING|"Sander-EP.csv"
interval=STRING|"10"
listmode=STRING|"1"
mon_files=STRING|"1"
mon_folders=STRING|"0"
new=STRING|"1"
newlistparameter=STRING|"DATEIUNDPFAD"
notsavestatus=STRING|"0"
onelistparameter=STRING|"DATEIUNDPFAD"
pass=STRING|"1"
passmode=STRING|"1"
required=STRING|"0"
saveresults=STRING|"0"
subfolders1=STRING|"0"
The main problem is :
When you try to pass the list of changed files to the task from trigger it is the list of files. One file name per line and each line ended with EOL (end-of-line) symbols. So TextFile variable can not find the file.
Generally it is the text and you must process it in the text loop.
But you configured the trigger to return only one filename. So you need to cut off the EOL characters from the filename variable. Look at step #4 of my example.
Oleg Yershov
gremlin
Posts: 35
Joined: Sun Jan 08, 2023 3:13 pm

Re: Read a Textfile , Append, Save Textfile

Post by gremlin »

Yes, thank you.
Now I understand.

Thanks Steven
Post Reply