Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Easy way to mass rename files? Post 19970 by Kelam_Magnus on Thursday 18th of April 2002 01:22:49 PM
Old 04-18-2002
TRUEST,

Your example would APPEND ".php" to the end of the original filename not replace the .php3 with .php

You are not accounting for the old extension needing to be removed.

PETER,

You need to look at the cut command that I have below. You can use the same options but use the -f 1,2 so that it will take the first two "fields" defined by the . as the delimeter!




Here is my contribution.

for name in `ls *.php3`
do
name1=` echo $name| cut -f 1 -d . `
mv $name1.php3 $name1.php
done

This will use the . which is the "field separator" for the first and last portions of the filename.

Here are my filenames that I used.
1one.php3
2.php3
3.php3
4four.php3


It will work on different length filenames provided they only have one . in the name.



Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Mass Copy/rename

Don't tell me DOS can do something UNIX can't do! I want to copy a number of files from one directory to another, and at the same time change the names. The name changes would be common, e.g., all files starting with the letter 'L' and ending in '30.NEW554', with the copied or new files also... (6 Replies)
Discussion started by: lwilsonFG
6 Replies

2. Shell Programming and Scripting

Mass Change content in all files

Hi, Are there any sample scripts to change content like file paths, profile paths etc., from test version to production , instead of changing one by one, i would like to pass the in file (prod version/Test version) to convert to test or prod verions. any help is appreciated!! ~R (1 Reply)
Discussion started by: terala
1 Replies

3. AIX

VI questions : mass changes, mass delete and external insert

Is it possible in VI to do a global change but take the search patterns and the replacement patterns from an external file ? I have cases where I can have 100,200 or 300+ global changes to do. All the new records are inside a file and I must VI a work file to change all of them. Also, can... (1 Reply)
Discussion started by: Browser_ice
1 Replies

4. UNIX for Dummies Questions & Answers

Need help on installing an EASY to use and easy to install command line text editor

Hi again. Sorry if it seems like I'm spamming the boards a bit, but I figured I might as well ask all the questions I need answers to at once, and hopefully at least get some. I have installed Solaris 10 on a server. The default text editors are there (vi, ex, ed, maybe others, I know emacs is... (4 Replies)
Discussion started by: EugeneG
4 Replies

5. Shell Programming and Scripting

bash script to rename in mass

Basically, I have a huge amount of files (ripped audiobooks) that all have the same garbage in their filenames. I'm wondering how to go about writing a bash script to mass rename them. Example filenames as they stand now: The First CD - 1x01 - Title 1.mp3 The First CD - 1x02 - Title 2.mp3... (4 Replies)
Discussion started by: audiophile
4 Replies

6. UNIX for Dummies Questions & Answers

Need help to mass rename files

Hi. I've got 75 mp3s that have the word 'Émission' in their filename. They are all in this format: Émission bla1 bla1.mp3 Émission bla2 bla2.mp3 Émission bla3 bla3.mp3 etc... I would just like to mass replace 'Émission' by 'Emission'; basically replace 'É' with 'E'. The rest of the... (10 Replies)
Discussion started by: Kingzy
10 Replies

7. Windows & DOS: Issues & Discussions

Windows mass copy files with same name in differnt folders

I have files existing with same names in the folders with date as display below c:\2010-09-10 <==== folder arr1.jpg arr2.jpg arr3.jpg arr4.jpg c:\2010-09-09 <==== folder arr1.jpg arr2.jpg c:\2010-09-08 <==== folder arr2.jpg arr3.jpg arr4.jpg ... (5 Replies)
Discussion started by: jville
5 Replies

8. Shell Programming and Scripting

mass renaming files with complex filenames

Hi, I've got files with names like this : _Some_Name_178_HD_.mp4 _Some_Name_-_496_Vost_SD_(720x400_XviD_MP3).avi Goffytofansub_Some name 483_HD.avi And iam trying to rename it with a regular pattern. My gola is this : Ep 178.mp4 Ep 496.avi Ep 483.avi I've tried using sed with... (8 Replies)
Discussion started by: VLaw
8 Replies

9. Programming

Minor editing of mass HTML files

Hello, I'm manipulating a batch of about 2,000 HTML files. I just need to make some small changes, but to all the files at once. For example, I want to delete the lines that have "embed_music" in all the files, or change all instances of the word "Paragraph" to "Absatz". This is my... (2 Replies)
Discussion started by: pxalpine
2 Replies

10. Shell Programming and Scripting

Rename mass files with text from first line

I have a few hundred text files that are currently numbered files. I would like to rename each one with the text from the first line in the file. I would prefer this is perl script rather than a one liner as it wil be after many alterations to the file via an existing script. Any help would be... (1 Reply)
Discussion started by: GWhizz
1 Replies
PATHINFO(3)								 1							       PATHINFO(3)

pathinfo - Returns information about a file path

SYNOPSIS
mixed pathinfo (string $path, [int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME]) DESCRIPTION
pathinfo(3) returns information about $path: either an associative array or a string, depending on $options. PARAMETERS
o $path - The path to be parsed. o $options - If present, specifies a specific element to be returned; one of PATHINFO_DIRNAME, PATHINFO_BASENAME, PATHINFO_EXTENSION or PATHINFO_FILENAME. If $options is not specified, returns all available elements. RETURN VALUES
If the $options parameter is not passed, an associative array containing the following elements is returned: dirname, basename, extension (if any), and filename. Note If the $path has more than one extension, PATHINFO_EXTENSION returns only the last one and PATHINFO_FILENAME only strips the last one. (see first example below). Note If the $path does not have an extension, no extension element will be returned (see second example below). If $options is present, returns a string containing the requested element. CHANGELOG
+--------+--------------------------------------------+ |Version | | | | | | | Description | | | | +--------+--------------------------------------------+ | 5.2.0 | | | | | | | The PATHINFO_FILENAME constant was added. | | | | +--------+--------------------------------------------+ EXAMPLES
Example #1 pathinfo(3) Example <?php $path_parts = pathinfo('/www/htdocs/inc/lib.inc.php'); echo $path_parts['dirname'], " "; echo $path_parts['basename'], " "; echo $path_parts['extension'], " "; echo $path_parts['filename'], " "; // since PHP 5.2.0 ?> The above example will output: /www/htdocs/inc lib.inc.php php lib.inc Example #2 pathinfo(3) example showing difference between null and no extension <?php $path_parts = pathinfo('/path/emptyextension.'); var_dump($path_parts['extension']); $path_parts = pathinfo('/path/noextension'); var_dump($path_parts['extension']); ?> The above example will output something similar to: string(0) "" Notice: Undefined index: extension in test.php on line 6 NULL NOTES
Note For information on retrieving the current path info, read the section on predefined reserved variables. Note pathinfo(3) is locale aware, so for it to parse a path containing multibyte characters correctly, the matching locale must be set using the setlocale(3) function. SEE ALSO
dirname(3), basename(3), parse_url(3), realpath(3). PHP Documentation Group PATHINFO(3)
All times are GMT -4. The time now is 11:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy