Robin version used for the guide: 0.9.0.5519
You can find the complete script here:
GitHub: Robin examples - Simple text and Compression
We are going to implement the following scenario:
We are going to create a simple text file which will include random generated text and then we are going to compress it.
During the guide I am going to showcase some practices we are thinking of establishing as best practices in our documentation so I would really appreciate your feedback!
It is always a good idea to store things like file/folder paths in variables.
This way your script can be easier to maintain as well as more dynamic.
Let’s say for example that you want to share your Robin script with a friend of yours.
Filepaths will most likely be different, and you want to minimize/eliminate repetitive work (re-setting of paths in this case).
For this example (and for the others to come) I will use a dedicated Robin folder which resides in my Desktop.
In order to be more dynamic I am going to get my Desktop path, which is a special folder:
After that we can store the path to the folder we are going to do our work in to a dedicated variable.
We do the same for our .txt file
See how more dynamic that is?
It may require some more lines of code at the beginning but it is clearly more maintainable and easier to distribute.
Now we need to create and populate our .txt file.
In the example I am going to create a 10-line text file with randomly generated text.
I will utilize a loop 10 times.
In each iteration a random string of characters will be generated and then it will be appended at the end of the file.
Just for the fun of it let’s read the file we generated and print its content in the console output:
After that we create a variable to hold the path to our .zip file (remember, good practices to make our scripts more clear, dynamic and easier to maintain ).
And finally we can compress our .txt file.
After executing the script, open your working folder and voila! There are our two files (.txt and .zip)!
A complete screenshot of the script file for reference: