0

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

Nopact
  • 3
  • 2
  • Does this answer your question? [Return value of x = os.system(..)](https://stackoverflow.com/questions/26005583/return-value-of-x-os-system) – shimo Jan 14 '20 at 11:43
  • Please check the return value of `os.system("rclone lsf backup_account:backup")`. – shimo Jan 14 '20 at 11:44
  • Using the proposed code: `x = subprocess.check_output(['whoami'])` returns a correct value. – Nopact Jan 15 '20 at 06:14
  • If copy paste `rclone lsf backup_account:backup` it returns: `Traceback (most recent call last): File "backup.py", line 18, in x = subprocess.check_output(['rclone lsf boxer3000:backup']) File "/usr/lib/python2.7/subprocess.py", line 216, in check_output process = Popen(stdout=PIPE, *popenargs, **kwargs) File "/usr/lib/python2.7/subprocess.py", line 394, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory` – Nopact Jan 15 '20 at 06:15

0 Answers0