I have a lot of files in subsubfolders. They all look like in.*.radiate, where * is just a number.
Is there a way to rename all of them with a single command to just in.radiate?
Either in linux or MATLAB?
I have a lot of files in subsubfolders. They all look like in.*.radiate, where * is just a number.
Is there a way to rename all of them with a single command to just in.radiate?
Either in linux or MATLAB?
If there's an easier way, I do not know, but here's a simple perl script that'll do the job for you:
#!/usr/bin/perl
use warnings;
use strict;
my $oldname = '*.radiate'; # Pattern of old filename. Edit if desired.
my $newname = 'in.radiate'; # New filename. Edit if desired.
foreach my $folder1 (glob("*"))
{
if (-d $folder1)
{
foreach my $folder2 (glob("$folder1/*"))
{
if (-d "$folder2")
{
print "Processing $folder2\n";
system("mv $folder2/$oldname $folder2/$newname");
}
}
}
}
Stick that into a file named, for example, rename.pl
in the directory where all of the subdirectories are, and run it with perl rename.pl
.
It has a bug/feature where it'll let you know if the folder being processesed doesn't contain a .radiate
file.
There are probably many shorter ways to do it, but this should be readable enough for "anyone" to edit if needed.
EDIT: Updated to traverse subdirectories of subdirectories, as I misread the original question. Tested it on my machine, and it works as intended on Linux Mint 17 with perl 5.18.2