[Python] How to copy a google file with Colaboratory?

Discussão em 'Python' iniciado por Stack, Fevereiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I need to copy a folder and its entire content (with subfolders) to another folder in Google Drive.

    I tried using Colaboratory like this:

    from google.colab import drive
    drive.mount('/content/drive')

    %cd /content/drive/MyDrive
    %cp -av FOLDER_TO_COPY NEW_FOLDER_COPY


    Folders and files are copied except for google files, which gives me the following error:
    cp: cannot open 'path_to_file' for reading: Operation not supported
    This happends for every .gdoc, .gsheet, .gslides, etc. I cannot convert those files to another format (like .docx or .xlsx) because some have complex formulas that I don't want to screw up.

    I also tried this :

    from shutil import copyfile

    copyfile('path_to_file_to_copy',
    'destination_path')


    But got:
    OSError: [Errno 95] Operation not supported: 'path_to_file'

    How can I copy Google files using Colaboratory ?

    Continue reading...

Compartilhe esta Página