File::Rename(3pm)
β¨ File::Rename β¨
okay bestie, gather round, because this is File::Rename(3pm) β a Perl extension for renaming multiple files, and it is lowkey iconic π
like, you have a whole pile of files and you want them all renamed by a rule instead of by hand like some kind of Victorian orphan. That's what this does. No cap.
πΈ SYNOPSIS πΈ
use File::Rename qw(rename); # hide CORE::rename
rename \@ARGV, sub { s/\.pl\z/.pm/ }, 1;
use File::Rename;
File::Rename::rename \@ARGV, '$_ = lc';
use File::Rename qw(:config no_require_order);
the first one imports rename and shadows the CORE one, because otherwise Perl's builtin rename is gonna be sitting there like "hi I'm the main character" and no. The second one doesn't import anything, it just calls the fully qualified File::Rename::rename. The third one pulls in config options with the :config tag and turns off require_order. Slay.
π¦ DESCRIPTION π¦
π USE OPTIONS π
When you use File::Rename, the stuff you pass in is split into two vibes: functions to be imported and configuration options.
The only function that gets exported is rename(). The configuration options have to be introduced by :config, and then they get handed straight off to File::Rename::Options. That's the whole tea. π
π§ FUNCTIONS π§
rename( FILES, CODE [, VERBOSE])β renames FILES using CODE. and if FILES is empty?? it reads the list of files from stdin instead. very demure, very mindful. πrename_files( CODE, VERBOSE, FILES)β renames FILES using CODE. (yes the argument order is different, no I will not be explaining why, it just is, periodt.)rename_list( CODE, VERBOSE, HANDLE [, FILENAME])β renames a list of files read from HANDLE, using CODE.
π OPTIONS π
FILESβ the list of files you wanna rename. forrenamethis must be an ARRAY reference, so like,\@ARGVnot@ARGV. don't come for me.CODEβ the subroutine that actually changes the file names. forrenameit's allowed to be a plain string, but everywhere else it's a code reference.VERBOSEβ a flag that prints the names of files that got successfully renamed. it's optional forrenamebecause she's flexible like that πHANDLEβ the filehandle you read the file names from.FILENAME(optional) β the name of the file that HANDLE is reading from.
π HASH π
Either CODE or VERBOSE can be a HASH of options. plot twist.
If CODE is a HASH, then VERBOSE gets ignored (rip) and the code comes from the _code key instead.
The other options are:
verboseβ same energy as VERBOSE up above. provided by-v.input_nullβ sets the input separator to\0when reading file names from stdin.no_actionβ prints the names of files that would be renamed but doesn't rename them, i.e. takes no action at all. provided by-n.over_writeβ lets files get over-written by the renaming. provided by-f.filename_onlyβ only applies the renaming to the filename component of the path, not the whole path. provided by-d.show_helpβ prints the help. provided by-h.show_manualβ prints the manual page. provided by-m.show_versionβ prints the version number. provided by-V.unicode_stringsβ enables theunicode_stringsfeature. provided by-u.encodingβ sets the encoding for filenames. provided by-u.
β EXPORT β
rename
that's it. that's the list. one (1) whole function. minimalism is the vibe. π«Ά
π ENVIRONMENT π
No environment variables are used. none. zero. the environment is untouched and unbothered. β¨
π SEE ALSO π
go read those too, bestie, they're the supporting cast π
π AUTHOR π
Robin Barker <RMBarker@cpan.org>
π Acknowledgements π
Based on code from Larry Wall. (yes, that Larry Wall. legend behaviour π)
Options -e, -f, -n were suggested by more recent code written by Aristotle Pagaltzis.
π DIAGNOSTICS π
Errors from the code argument are not trapped. so like, if your CODE dies, it dies, and nobody is catching it for you. it's giving "you're on your own babe". π
πΈ COPYRIGHT AND LICENSE πΈ
Copyright (C) 2004, 2005, 2006, 2011, 2018, 2021, 2022, 2023 by Robin Barker
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.
and that's the whole page, bestie π this one's from perl v5.36.0, dated 2024-01-01, and it lives at File::Rename(3pm) β go rename something, you absolute icon π
β¨
π¦ where this page comes from
- debian trixie: rename 2.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: rename 2.02-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: rename 2.02-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms