Re: Removing a space from file name
Smoot Carl-Mitchell via beginners <[email protected]> Mon, 17 Feb 2025 13:12:17 -0700
| Newsgroups | gmane.comp.lang.perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 2025-02-17 at 12:38 -0500, hput wrote:
> I have several hundred *.jpg files with this pattern
>=20
> Actual example:
>=20
> =C2=A0=C2=A0 'AtlantaVisitAndGrandmaHands 056.jpg'
>=20
> The numbers vary, of course, but the alpha part and number of digits
> after the space is the same in all *.jpg files
>=20
> I have hundreds of these all in one directory.=C2=A0 Not something you'd
> want to do one at a time.
Something like:
while (<*>) {
rename $_, "$1$2.jpg" if $_ =3D~ /(.+) (.+)\.jpg/;
}
The RE matches any filename with a single space character and the .jpg
ending. I made the $_ explicit for clarity.
--=20
Smoot Carl-Mitchell
System/Network Architect
voice: +1 480 922-7313
cell: +1 602 421-9005
[email protected]
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/