Edit a text file

Discuss RoboTask here
Post Reply
Gekseppe
Posts: 16
Joined: Tue Sep 02, 2008 4:45 am
Location: Iceland

Edit a text file

Post by Gekseppe »

Hi;

I would need some help in writing a task with the following purpose:

1) monitor recursively a folder;
2) in case of new files, for each file, remove the following text from the header (the first 45 chars of the file):

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

3) save edited files in a new folder;
4) delete original files;
5) send new files by mail.

Any help will be really appreciated !
Oleg
Site Admin
Posts: 3051
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Edit a text file

Post by Oleg »

Can you send me an example of such file (oleg (at) robotask.com)?
I think that this job can be solved by using BASIC script (removing of 45 chars from header).

In order to implement the rest steps look at the following actions:
File loop
Text loop
Delete file
Send email
and
File monitor triggering event
Gekseppe
Posts: 16
Joined: Tue Sep 02, 2008 4:45 am
Location: Iceland

Edit a text file

Post by Gekseppe »

You got it: thanks !
Oleg
Site Admin
Posts: 3051
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Edit a text file

Post by Oleg »

My example of Basic script is below.

Code: Select all

Sub Main
  Dim in_file As String
  Dim out_file As String
  Dim buf As Byte
  Dim i As Long

  in_file = RoboTaskApp.ExpandText("{in_file}")
  out_file = RoboTaskApp.ExpandText("{out_file}")
  'in_file = "C:\incoming\SALE-NO-NA100249-5958.edi.sign"
  'out_file = "C:\incoming\SALE-NO-NA100249-5958_1.edi.sign"

  Open in_file For Binary Access Read As #1
  Open out_file For Binary Access Write As #2

  For i =1 To 45 'skip 45 chars
    Get #1, ,buf
  Next

  While True  'skip all CR & LF after 45 chars
    Get #1, ,buf
    If buf >= 20 Then
      Put #2, ,buf
      Exit While
    End If
  Wend

  While Not EOF(1)
    Get #1, ,buf
    Put #2, ,buf
  Wend

  Close #1
  Close #2

End Sub
This script copies the original file and cuts 45 chars from header.
I've sent the example via email.
Of course this task requires BASIC plugin for RoboTask.
Download it here
Gekseppe
Posts: 16
Joined: Tue Sep 02, 2008 4:45 am
Location: Iceland

Edit a text file

Post by Gekseppe »

Ouch !!! I'm currently using version 3.1 of Robo Task and Basic Plugin seems to work with version >= 4.1

Do you think there's a way to overcome this ?

Many thanks
Oleg
Site Admin
Posts: 3051
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Edit a text file

Post by Oleg »

Gekseppe
Posts: 16
Joined: Tue Sep 02, 2008 4:45 am
Location: Iceland

Edit a text file

Post by Gekseppe »

As usual great support !

Many thanks for your appreciated help: now I just get what I needed !

Post Reply