I want to write a script for automatic backing up some documents on my raspberry pi to a google drive. Therefore I installed rclone and it seems to work well. For organisation purpose I want to create for every upload a new folder with a 3 digit number e.g 001, 002, 003, ... This is my code so far:
import os
print("Exisiting folders:")
print(os.system("rclone lsf backup_account:backup"))
print("Create new folder...")
createFolder = os.system("rclone mkdir backup_account:backup/003")
print("Exisiting folders:")
folders = str(os.system("rclone lsf backup_account:backup"))
print(type(folders))
print(len(folders))
First I print the already existing folders in the google drive directory "backup". Second I create a new folder (in this example it is a static number and will be changed to a dynamic one, once the rest is working) Third I print the existing folders once again to check if everything worked fine.
Up to here, everything indeed works well and i get a printout like this:
Existing folders:
001/
002/
0
Create new folder...
Existing folders:
001/
002/
003/
<type 'str'>
1
As you see, it gives the folders as a string, if i leave out the Str() it returns a int. what I don't understand is, that the len(folders) = 1.
What I want is: Check in the beginning the existing folders and create a new one(following the numbering schema) and then copy the backup files to this new folder. As the script wont be running all the time, i cannot store anything in a variable.
Any hints on how to put the existing folders into a list, array, ... to find the last element/highest number/...?
Running raspbian buster