Discuss this help topic in SecureBlackbox Forum

Clouds: Get directory structure and file list

The first step is to get the root folder of the account. Call the TElGoogleDriveDataStorage.AcquireObject() method without parameters and cast the returned object to TElGoogleDriveFolder type. Use the object's methods to perform operations with files and folders located in the root directory of Google Drive service. When the object is not needed anymore, call its Release() method.

C#:


TElGoogleDriveDataStorage storage = new TElGoogleDriveDataStorage();
...
TElGoogleDriveFolder root = storage.AcquireObject() as TElGoogleDriveFolder;
Console.WriteLine("Root: {0}", root.Name);
root.Release();

Once you have a folder object, you can use its methods to list the folders and files contained in this folder. There are three methods available:

  1. TElGoogleDriveFolder.ListFolders() - lists only subfolders, which are located in the folder

    C#:

    
    TElGoogleDriveDataStorage storage = new TElGoogleDriveDataStorage();
    ...
    TElGoogleDriveFolder root = storage.AcquireObject() as TElGoogleDriveFolder;
    TElDataStorageObjectList list = new TElDataStorageObjectList();
    root.ListFolders(list);
    
    Console.WriteLine("Listed {0} folders:", list.Count);
    for (int i = 0; i < list.Count; i++)
    {
        TElGoogleDriveFolder folder = list.get_Objects(i) as TElGoogleDriveFolder;
        Console.WriteLine(" - {0} ({1})", folder.Name, folder.ID);
    }
    
    list.Dispose();
    

  2. TElGoogleDriveFolder.List() - gets the list of all the objects, which are located in the folder including subfolders

    C#:

    
    TElGoogleDriveDataStorage storage = new TElGoogleDriveDataStorage();
    ...
    TElGoogleDriveFolder root = storage.AcquireObject() as TElGoogleDriveFolder;
    TElDataStorageObjectList list = new TElDataStorageObjectList();
    root.List(list);
    
    Console.WriteLine("Listed {0} objects:", list.Count);
    for (int i = 0; i < list.Count; i++)
    {
        TElGoogleDriveDataStorageObject obj = list.get_Objects(i) as
                                              TElGoogleDriveDataStorageObject;
        Console.WriteLine(" - {0} ({1})", obj.Name, obj.ID);
    }
    
    list.Dispose();
    

  3. TElGoogleDriveFolder.ListTrashed() - gets the list of all trashed objects (files, folders and documents), contained in the folder.

All of the above methods accept an instance of the TElDataStorageObjectList class, which is filled in the methods with different types of objects. TElGoogleDriveFolder.ListFolders() method fills in the list with objects of the TElGoogleDriveFolder class. TElGoogleDriveFolder.List() and TElGoogleDriveFolder.ListTrashed() methods fill in the list with objects of different types (TElGoogleDriveFile, TElGoogleDriveDocument, TElGoogleDriveFolder), all of them derived from the TElGoogleDriveDataStorageObject class.

Please note that the list is not cleared by the above List*() methods, and new objects are appended to the list.

When the list is destroyed/disposed, it also destroys/disposes the contained objects. So, if you need a folder or a file object to use them after the list destroyed/disposed, you need to clone the object and use the copy.

Also, it's possible to store not objects but their IDs. When you need to perform any operation with a file or a folder with a known ID, it's very easy to get its object by calling TElGoogleDriveDataStorage.AcquireObject() method and passing the ID to it.

How To articles about Google Drive cloud

Discuss this help topic in SecureBlackbox Forum