Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Renames Tekla Structures pointcloud files to be human readable
use Mojo::Base -base;
use Mojo::Util qw(getopt);
use Mojo::File;
use Mojo::DOM;
getopt 'p|path=s' => \my $path;
sub main {
# look in xml elements for laserscans that have hashes for names, then rename.
my $file = Mojo::File->new($path, 'pointclouds.xml');
my $dom = Mojo::DOM->new($file->slurp);
for my $e ($dom->find('PointCloudData')->each) {
$e->{Folder} = rename_files($e) and $e->{Hash} = '' if $e->{Hash};
# save xml file so we don't try to rename the pointclouds again
sub rename_files {
# rename pointcloud folder and database file
my $e = shift;
my $newname = $e->{Folder} =~ s/$e->{Hash}/$e->{Name}/r;
say "renaming: $e->{Folder} to:\n$newname";
rename $e->{Folder}, $newname || die ("Couldn't rename $e->{Folder}");
rename $e->{Folder}.'.db', $newname.'.db' || die ("Couldn't rename $e->{Folder}.db");
return ($newname);
main() if $path || die 'Please enter a path to the example files.';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.