Have you ever wanted to rename more than one file at a time? Have you ever wanted to be able to rename a group of files based on a regular expression? Well the script below will let you do just that. Save the above code into a file called rename. Make sure that the permissions are set correctly so that you can execute the script.
If Perl is somewhere else, you'll need to change the first line to point to where Perl is installed on your system. You can actually pass any Perl expression through to perlexpr allowing you to do more complex file renaming actions. The files argument is a list of filenames that you want to change.
Change all the files prefixed with the text mah and suffixed with. Many people who come from the world of system administration and Unix or Linux scripting, will try to keep using the regular unix commands of rm , cp and mv for these operations.
Calling them either with back-tick or with system , even when writing Perl scripts. That works on their current platform, but that gives up one of the key benefits Perl brought to the world of Unix system administration. Let's see how can we execute these operations with Perl in a platform-independent way, and without shelling out.
It removes one or more files from the file system. It is similar to the rm command in Unix or the del command in Windows. For full documentation see perldoc -f unlink. The standard way to copy a file is to use the copy function of File::Copy. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science.
Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related Hot Network Questions.
Question feed. Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings.
0コメント