9

I have recently been saving my files to Wolfram Cloud for convenience as I am using different computers for work.

I would like to routinely back up the files to my local desktop.

If I were to do this I would need to click each file in the cloud one by one and manually click download.

Is there a way I can write a notebook to do this automatically as I have 100+ files and I would like to do this job quite regularly?

user64494
  • 26,149
  • 4
  • 27
  • 56

2 Answers2

11

You can use CloudObjects and CloudDirectory to find your files:

objects = CloudObjects @ CloudDirectory[]
{CloudObject["https://www.wolframcloud.com/obj/carlw/Base"], CloudObject[
"https://www.wolframcloud.com/obj/carlw/Copied Files"], CloudObject[
"https://www.wolframcloud.com/obj/carlw/Marathon"], CloudObject[
"https://www.wolframcloud.com/obj/carlw/Resources"], CloudObject[
"https://www.wolframcloud.com/obj/carlw/marathon"], CloudObject[
"https://www.wolframcloud.com/obj/carlw/trash"]}

Here is the first cloud object in the "Copied Files" directory:

obj = First @ CloudObjects[objects[[2]]]
CloudObject["https://www.wolframcloud.com/obj/carlw/Copied Files/01-starting-out-elementary-arithmetic-exercises.nb"]

Once you find the right directory, you can copy them with CopyFile:

CopyFile[obj, FileNameTake @ Information[obj]["Path"]]
"/Users/carlw/Desktop/01-starting-out-elementary-arithmetic-exercises.nb"
Carl Woll
  • 130,679
  • 6
  • 243
  • 355
5

This is the code I ended up using. It also looks into directories 1 level and copies those files too.

localBackupPath = "C:\\Users\\";
objects = CloudObjects@CloudDirectory[];
type = Information[#, "FileType"] & /@ objects;
allObjects = 
  Flatten[MapThread[
    If[#2 === Directory, CloudObjects[#1], #1] &, {objects, type}]];

CopyFile[#, 
   FileNameJoin[{localBackupPath, 
     Information[#, "DisplayName"]}]] & /@ allObjects