The following is a recipe for a comparison based on filenames alone, not based on file modification times or even content checksums. But it's a start :) Also, the below is to compare two directories that are both on Google Drive, but you can easily adapt it by generating a list of your local files instead with some call to ls
. (So obviously, the below is a recipe for Linux.)
1. Install and configure drive
drive
is a Linux command line client for Google Drive. The easiest is to install it from a package.
After that:
Change into the directory on your computer that includes your whole files synced from Google Drive:
cd /home/user/example-dir/
Initialize drive
with access to your Google Drive. This will ask you to visit a URL and paste the auth code you get there, and save this in a config file in the current directory.
drive init
2. Comparing directories
I found that for large Google Drive folders (36 GiB of small files in my case), starting by comparing directories and fixing cases of missing directories was a good first step. (Also because drive
has no option to copy directories without the files inside between two Google Drive folders. Not a problem if you compare between local and remote files only.)
drive list -directories -recursive -no-prompt -sort name "source dir" > DirDiff.1-source.txt
drive list -directories -recursive -no-prompt -
sort name "dest dir" > DirDiff.2-dest.txt
vim -es +"%s/^\/source dir\///g" +"wq" DirDiff.1-source.txt
vim -es +"%s/^\/dest dir\///g" +"wq" DirDiff.2-dest.txt
The drive
command obtain lists of directories from Google Drive, and the vim
commands remove the differing base directories from each path so that comparison will work properly.
Now to list the directories that are only in the source tree:
comm -23 <(sort < DirDiff.1-source.txt) <(sort < DirDiff.2-dest.txt) > DirDiff.3-missing.txt
And to show the directories that are only in the destination tree:
comm -13 <(sort < DirDiff.1-source.txt) <(sort < DirDiff.2-dest.txt) > DirDiff.4-added.txt
About using comm
like this, see here.
3. Comparing files
This works very similar to comparing directory trees:
drive list -recursive -no-prompt -sort name "source dir" > 1-source-files.txt
drive list -recursive -no-prompt -sort name "dest dir" > 2-dest-files.txt
vim -es +"%s/^\/source dir\///g" +"wq" DirDiff.1-source.txt
vim -es +"%s/^\/dest dir\///g" +"wq" DirDiff.2-dest.txt
To show the files only in the source tree:
comm -23 <(sort < FileDiff.1-source.txt) <(sort < FileDiff.2-dest.txt) > FileDiff.3-missing.txt
To show the files only in the destination tree:
comm -13 <(sort < FileDiff.1-source.txt) <(sort < FileDiff.2-dest.txt) > FileDiff.4-added.txt
Best Answer
I know this is an old question and "Google Drive" is now "Backup and Sync from Google", however it still applies. It took me a while to figure out this solution so I could sync my projects without including dependencies or caches.
As I understand it, the issue is that you want to sync a folder, however there are some sub folders or files within the folder you do not want to sync, but would like to keep on your local machine (not Google Drive). Right now, Google Drive only does the opposite (it will allow you to keep a copy on Google Drive, but not on your local machine).
One way around this is to make symbolic links in the folder you want to sync and Google Drive will ignore them (tested on Windows 10 with the mklink command).
For example, let's say this is your file structure...
Now, let's say that you want MainFolder\SubFolderB\ and MainFolder\FileB.ext on your local machine, but not Google Drive. Make a "MainFolder" somewhere outside of your Google Drive folder (eg: C:\MainFolder\), then move SubFolderB and FileB.ext to the newly created folder.
Your file structure should now look like....
Next, we'll want to create the symbolic links. For this example, you'd run the Command Prompt in Administrator mode and run the following commands:
Now your file structure will be:
And that's it! The folders/files you symbolic linked will still be on your local machine, however it will not be stored/sync'd to your remote Google Drive.
EDIT
Posted the actual answer here instead of linking it.