#!/usr/bin/perl use strict; use JSON; my @data = <>; my $json = JSON->new->decode(join('',@data)); my $folder = {}; my $folderids = {}; if (exists $json->{'items'}) { foreach my $item (@{$json->{'items'}}) { if ($item->{'mimeType'} eq 'application/vnd.google-apps.folder') { my $foldername = $item->{'title'}; while (exists $folder->{$foldername}) { $foldername .= '~'; } $folder->{$foldername} = $item->{'id'}; $folderids->{$item->{'id'}} = $foldername; printf "%20s [FOLDER], %s\n", $foldername, $item->{'id'}; } } foreach my $item (@{$json->{'items'}}) { next if ($item->{'kind'} ne "drive#file"); next if ($item->{'mimeType'} eq 'application/vnd.google-apps.folder'); next if ($item->{'labels'}->{'trashed'} eq 'true'); printf "%20s , %9s ", $item->{'title'}, $item->{'fileSize'}; if (exists $item->{'parents'}) { foreach my $parent (@{$item->{'parents'}}) { if (exists $folderids->{$parent->{'id'}}) { print "," . $folderids->{$parent->{'id'}}; } } } print "\n"; } }