Search code examples
google-colaboratorydrive

Get path of file in Google Drive


I have a file located at content/drive/Shareddrives/Bla/Bla/Bla/Bla/myfile.py

Is there an easy way to get the path of this file ? I can have like 10 subfolders and writing the path manually each time is a real pain.


Solution

  • I suggest using the os.walk for this task like this:

    import os
    
    for root, dirs, files in os.walk("/content/drive"):
        for name in files:
            if name == "myfile.py":
                print(os.path.join(root, name))
    

    /e: You can also copy a file path to clipboard from the left side menu Files. Right mouse click on chosen file and Copy path. Screenshot below, but with Polish language:

    enter image description here