Gdrive: Delete file by name

Created on 4 Sep 2019  路  3Comments  路  Source: prasmussen/gdrive

Good afternoon, I would like to ask the developers, so in a future release, please add the option to delete a file or directory by name, because working with script and this option would greatly reduce the number of lines and jerry-rig to make the script runs as it should.
Another option I would like to ask if it were possible is a parameter like grive2, --no-remote-new that prevents the creation of the same directory on a new upload and overwrites its contents.
Thanks in advance.

T谩cio Andrade

Most helpful comment

deletebyFileName.sh

#!/bin/sh
name = $1
if [ -z "$name"]
then 
 echo You have to enter file name to search
fi
gdrive list -q "name contains '${name}'" -m 100 --order name | sed -rn 's/([0-9A-Za-z_\-]+)\s.*/\1/p' > list.log
while IFS='' read -r line || [[ -n "$line" ]]; do
 gdrive delete  "${line}"
done < list.log
rm -rf list.log
echo -ne "Fin" 

./deletebyFileName.sh ".mkv"

All 3 comments

deletebyFileName.sh

#!/bin/sh
name = $1
if [ -z "$name"]
then 
 echo You have to enter file name to search
fi
gdrive list -q "name contains '${name}'" -m 100 --order name | sed -rn 's/([0-9A-Za-z_\-]+)\s.*/\1/p' > list.log
while IFS='' read -r line || [[ -n "$line" ]]; do
 gdrive delete  "${line}"
done < list.log
rm -rf list.log
echo -ne "Fin" 

./deletebyFileName.sh ".mkv"

Thank you! In the case of this environment I am using Windows Server! My goal is to use a push client to avoid ransomware .... Previously I used megatools, but this client hired a 100GB Google Drive account and asked him to find a compatible client.

Would you know how to do this using CMD or PowerShell?

Needs to skip the first line in the file log since it's "Id" and gives off an error because the fileId is obviously non existant, but it is a nice base.
This is how I modified it:

#!/bin/bash
name=$1
if [ -z "$name" ]
then
    echo You have to enter file name to search
    exit
fi
/home/user/gdrive list -q "name contains '${name}'" -m 100 --order name | sed -rn 's/([0-9A-Za-z_\-]+)\s.*/\1/p' > /tmp/glist.log
while IFS='' read -r line || [[ -n "$line" ]]; do
    /home/user/gdrive delete  "${line}"
done < /tmp/glist.log
rm -rf /tmp/glist.log

Not so expert about shell scripting so no idea for now about removing first line of output, but not having an exit in the parameter check will lead to basically remove every file in google drive :open_mouth:
Ask me how I found out :tongue:
Luckily it was just a testing config

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GaryFurash picture GaryFurash  路  3Comments

msnoon picture msnoon  路  6Comments

ijunaid8989 picture ijunaid8989  路  4Comments

4getit picture 4getit  路  4Comments

uzvermode picture uzvermode  路  3Comments