I'd like to be able to programmatically fetch the name of a Google Drive file by ID using rclone

What is the problem you are having with rclone?

When downloading a file from Google Drive using its file ID, I'd like to be able to programmatically determine its filename (and whatever other information might be available) before actually downloading the file. E.g., so that I can display to the user what file is being downloaded, etc.

I learned from this thread, that I can use the "-i" option to see the filename before doing the actual downloading. The problem with using "-i" is that it puts rclone into interactive mode, so if I use this option while running rclone from another program, the rclone command will hang waiting for input from stdin.

I've figured out that I can work around this by feeding /dev/null into the rclone, like so:

rclone -i backend copyid my-drive: my-file-id path/to/output/dir < /dev/null

If I do the above, rclone will output the filename, along with some other verbiage to stderr, and then terminate with a non-zero exit code. I can programmatically do the above, capture the output written to stderr and parse out the filename from stderr. This works, but this approach is far from ideal. E.g., if there is a real error, dealing with the error programmatically becomes "nuanced".

It would be great if there were just some option, other than "-i" that would tell rclone to output any information it can about the file (including its filename) to stdout without downloading the file, and then to exit with a zero exit status if there were no errors in fetching the file information.

Run the command 'rclone version' and share the full output of the command.

rclone v1.60.0
- os/version: darwin 10.15.4 (64 bit)
- os/kernel: 19.4.0 (x86_64)
- os/type: darwin
- os/arch: amd64
- go/version: go1.19.2
- go/linking: dynamic
- go/tags: none

Which cloud storage system are you using? (eg Google Drive)

Google Drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone backend -i copyid poolq-uploads: '1t49fnYgmEd4ITJjMsRfcHXnB8f3WSBdC'  test-dir/  < /dev/null

The rclone config contents with secrets removed.

I'm not having a problem with my config. Everything is working exactly as documented. I'm just trying to find out if there is an undocumented feature that will do what I need.

A log from the command with the -vv flag

$ rclone -vv backend -i copyid poolq-uploads: '1t49fnYgmEd4ITJjMsRfcHXnB8f3WSBdC'  test-dir/ < /dev/null
2022/11/06 20:18:13 DEBUG : rclone: Version "v1.60.0" starting with parameters ["rclone" "-vv" "backend" "-i" "copyid" "poolq-uploads:" "1t49fnYgmEd4ITJjMsRfcHXnB8f3WSBdC" "test-dir/"]
2022/11/06 20:18:13 DEBUG : Using config file from "/Users/nessus/.config/rclone/rclone.conf"
2022/11/06 20:18:13 DEBUG : Creating backend with remote "test-dir/"
2022/11/06 20:18:13 DEBUG : fs cache: renaming cache item "test-dir/" to be canonical "/Users/nessus/s/mysrc/scala/scala-cli-examples/test-dir"
rclone: copy "C5KC3ACXX.2.1.fastq.gz"?
y) Yes, this is OK (default)
n) No, skip this
s) Skip all copy operations with no more questions
!) Do all copy operations with no more questions
q) Exit rclone now.
y/n/s/!/q> 2022/11/06 20:18:13 Failed to read line: EOF

hi,

might try
rclone lsf poolq-uploads: --format='pi'

Thanks, but your suggested solution just lists the top-level folders on poolq-uploads. I have no idea where on the Google Drive the file is located. All I know is its Google Drive file ID.

--dry-run may work for you?

$ rclone --dry-run backend copyid drive: 1IPRkWlaXRZ5feEx3wXXXXXX /tmp/
2022/11/07 10:41:06 NOTICE: test.txt: Skipped copy as --dry-run is set (size 12)

Ah, yes, thanks! The output of "--dry-run" will do the job nicely.

1 Like