#! /usr/bin/perl # /******************************************************************************* # * Licensed Materials - Property of IBM # * (c) Copyright IBM Corporation 2005, 2012. All Rights Reserved. # * # *******************************************************************************/ # Script to find a file/folder in a workspace. # Script usage: findfile.pl {file pattern} {workspace name/alias/uuid} {repoUri} # Script usage example: findfile.pl my*file.txt myWorkspace1 repoUri # Requirements: # Install JSON module from http://search.cpan.org/~makamaka/JSON-2.53/lib/JSON.pm use JSON; my $filePattern = $ARGV[0]; my $workspace = $ARGV[1]; my $repoUri = $ARGV[2]; # Get all the components for the workspace my $result = `lscm list components $workspace -r $repoUri --json`; quitOnError($?, $result); # Decode the result my $json = decode_json($result); # Loop through the components my $ws = $json->{workspaces}[0]; foreach my $component (@{$ws->{components}}) { my $componentId = $component->{"uuid"}; findPatternInComponent($filePattern, $workspace, $componentId, $repoUri); } # # Routine that prints the matching file/folder found in the component # sub findPatternInComponent { my $filePattern = shift; my $workspace = shift; my $component = shift; my $repoUri = shift; # Get all the files/folders for the component my $result = `lscm list remotefiles $workspace $component -r $repoUri --depth - --json`; quitOnError($?, $result); # Decode the result my $json = decode_json($result); # Loop through the file/folders foreach my $entry (@{$json->{"remote-files"}}) { # Get the file/folder name if ($entry->{"path"} =~ "\(\[\^/\]\+\)/\?\$") { # match the file pattern if ($1 =~ $filePattern) { print $entry->{"path"} . "\n"; } } } } # # Routine that prints the error message and quits # sub quitOnError { my $error_code = shift; my $error = shift; if ($error_code != 0) { print $error . "\n"; exit($error_code); } }