Copy name of one file to another (with different extension)

Would you like Bulk Rename Utility to offer new functionality? Post your comments here!

Copy name of one file to another (with different extension)

Postby yarali46 » Tue Jan 03, 2012 10:15 pm

Hi,

here is my use case for my suggestion. i have 2 files with similar names, and i want them to have exactly the same name, except the extension. usually the case when i have video files and subtitle files in same folder, and mostly video players require file name of the subtitle to be the same as the video file in order to load the correct subtitle automatically. In this case i should choose the "source extension" and "destination extension". then i should choose the "from character" and "to character" of the source extension to be compared with the "from character" and "to character" of the destination extension. then BRU should find files which have the same characters in these ranges and rename the destination file.

here is the example. i have 6 files in the folder:

TV.Series.SE01.E01.avi
TV.Series.SE01.E02.avi
TV.Series.SE01.E03.avi
TVSeries Season1-Episode01.srt
TVSeries Season1-Episode02.srt
TVSeries Season1-Episode03.srt

here are the parameters i should enter:
source extension: avi
destination extension: srt
from character of source extension: 17
to character of source extension: 18
from character of destination extension: 25
tocharacter of destination extension: 26

BRU will find 01 02 and 03 in both files, and move avi names to the srt names accordingly. after the operation, my files should have the names:

TV.Series.SE01.E01.avi
TV.Series.SE01.E02.avi
TV.Series.SE01.E03.avi
TV.Series.SE01.E01.srt
TV.Series.SE01.E02.srt
TV.Series.SE01.E03.srt
yarali46
 
Posts: 2
Joined: Tue Jan 03, 2012 10:00 pm

Re: Copy name of one file to another (with different extension)

Postby Stefan » Wed Jan 04, 2012 9:43 pm

For the challenge "Rename SRT files like AVI files "

FROM:
TV.Series.SE01.E01.avi
TV.Series.SE01.E02.avi
TV.Series.SE01.E03.avi
TVSeries Season1-Episode01.srt
TVSeries Season1-Episode02.srt
TVSeries Season1-Episode03.srt

TO:
TV.Series.SE01.E01.avi
TV.Series.SE01.E02.avi
TV.Series.SE01.E03.avi
TV.Series.SE01.E01.srt
TV.Series.SE01.E02.srt
TV.Series.SE01.E03.srt

DO:

(Best make an backup of all your files first!)


1.) be sure that for all *.avi there is an corresponding *.srt file
If there are more AVi then SRT files or vice versa you will mess up your files.


2.) Selection(12) "*.srt" to see *.SRT files only
3.) select All and use context menu > Clipboard Copy > "FileName + Ext"
4.) open Excel and paste this list to column A
Code: Select all
         [                 A            ]    [            B          ]   [                     C                            ]   
1         TVSeries Season1-Episode01.srt
2         TVSeries Season1-Episode02.srt
3         TVSeries Season1-Episode03.srt


5.) Selection(12) "*.avi" to see *.AVI files only
6.) select All and use context menu > Clipboard Copy > "FileName"
7.) switch to Excel and paste this list to column B
Code: Select all
         [                 A            ]    [            B          ]   [                     C                            ]   
1         TVSeries Season1-Episode01.srt         TV.Series.SE01.E01
2         TVSeries Season1-Episode02.srt         TV.Series.SE01.E02
3         TVSeries Season1-Episode03.srt         TV.Series.SE01.E03


8.) in column C type
= A1 & "|" & B1 & ".srt"

and copy this to all columns down to get:
Code: Select all
         [                 A            ]    [            B          ]   [                     C                            ]   
1         TVSeries Season1-Episode01.srt         TV.Series.SE01.E01         TVSeries Season1-Episode01.srt|TV.Series.SE01.E01.srt
2         TVSeries Season1-Episode02.srt         TV.Series.SE01.E02         TVSeries Season1-Episode02.srt|TV.Series.SE01.E02.srt
3         TVSeries Season1-Episode03.srt         TV.Series.SE01.E03         TVSeries Season1-Episode03.srt|TV.Series.SE01.E03.srt


The C column is used to rename "TVSeries Season1-Episode01.srt" TO "TV.Series.SE01.E01.srt" and all other files according too.
So double check if this all makes sense and if all file pairs are OK!!!



9.) select the C column and paste this as text to an text file:
Code: Select all
TVSeries Season1-Episode01.srt|TV.Series.SE01.E01.srt
TVSeries Season1-Episode02.srt|TV.Series.SE01.E02.srt
TVSeries Season1-Episode03.srt|TV.Series.SE01.E03.srt

Double check if all file pairs are in sync!!!

10.) In BRU use the "Renaming From A Text File" feature
to rename "TVSeries Season1-Episode01.srt" TO "TV.Series.SE01.E01.srt"

Code: Select all
        1. Select the folder which contains the objects you wish to rename.
        2. Select the files you wish to process (use CTRL or SHIFT to select multiple files).
        3.  Enter the renaming criteria.
             Here, click the Import option on the File menu and load your file.
             If the file is valid then you will see the "new name" column reflecting the contents of the text file.
        4. Hit the Rename button. (This button is not enabled unless you have selected one or more files/folders to rename!)


Read the help about "Renaming From A Text File":
To use this facility, create a text file in for the correct format, for example:

Track001.mp3|Headlong.mp3
Track002.mp3|Rushes.mp3
TRACK003.mp3|AnywhereIs.mp3

As you see, there is one entry per line.

Next, click the Import option on the File menu and load your file. If the file is valid then you will see the "new name"
column reflecting the contents of the text file.




HTH? :D


Search Google to find out more how to work with Excel.
For example i have found an web side about Excel to help you using it: http://www.mrexcel.com/articles/function-to-merge-two-columns.php
IF that side is down, please find an picture of it there >>> http://forentmp.lima-city.de/BRU_Excel_Merge2Columns-c16.png



Find me: Rename from a list "Renaming From A Text File" renaming pairs rename textfile textlist excel sheet


###############################################################################################

- - - NEW
Use "Renaming From A Text File" and a spreadsheet to do the math, e.g to increase numbers:
http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=4&t=1935&p=4931#p4931

Can I add a specific value to a non-sequential numeric suffix in a file?
Can I add a value of 25 to each, such that...

IMAGE001 becomes IMAGE026
IMAGE002 becomes IMAGE027
IMAGE017 becomes IMAGE042
IMAGE034 becomes IMAGE059

Yes, you can do that by utilizing the "Renaming From A Text File" feature

old name | new name

To get the new names you can use a spreadsheet tool.
For your case, to increase a number, do this steps in an spreadsheet:

Column A: IMAGE001.jpg
The original name
In BRU select all files and use context menu > Clipboard Copy > "FileName + Ext"
Then open e.g. Excel and paste this list to column A


Column B:
i have left empty for no real reason, but i keep it here too since i have already taken the screen shot

Column C: =left( A1 ; len(A1) - 7 )
Name part without trailing 3 digits number:
Take whole name from left till 7 from the right (number + dot + extension => 3+1+3=7)
>> IMAGE


Column D: =right( left( A1 ; len(A1) - 4 ) ; 3 )
Number only without leading chars:
Take whole name from left without right 4 (dot + ext) >> IMAGE001
and from that the last 3 from the right (the number) >> 001


Column E: =right( "000" & D1 + 25 ; 3)
Add value of "25" to each number:
Put a lot of leading zeros plus the origin number as in column D "001", plus the addition "25", >> 0001 >> 0026
then take the last 3 from the right only >> 026


Column F: =right( A1 ; 4 )
Get the extension:
Take the right 4 of the original name (dot + ext) >> .jpg


Column G: =A1 & "|" & C1 & E1 & F1
Glue all together:
Old Name "A1", plus pipe symbol '|' for BRU, plus Name part "C1", plus new number "E1", plus extension "F1"
>> IMAGE001.jpg|IMAGE026.jpg



See a picture
http://imageshack.us/photo/my-images/827/excelbruincreasenumber.png/

Next select the G column and copy and paste it to an text file for "Renaming From A Text File" BRU option.
IMAGE001.img|IMAGE026.img
IMAGE002.img|IMAGE027.img
IMAGE017.img|IMAGE042.img
IMAGE034.img|IMAGE059.img


I have done the code to work with different name part lengths too:
IMAGE abc 001.img|IMAGE abc 026.img
IMAGE defgh 002.img|IMAGE defgh 027.img
IMAGEijkl 017.img|IMAGEijkl 042.img
IMAGEmnop034.img|IMAGEmnop059.img



##############################


Merge to lists of file names by utilizing PowerShell instead of Excel:


FileList_originNames.txt contains
A.png
B.png
C.png
FileList_WantedNames.txt contains
x.png
y.png
z.png

Utilize PowerShell
PS C:\temp\workingDir> $origin   = Get-Content   FileList_originNames.txt
PS C:\temp\workingDir> $wanted = Get-Content   FileList_WantedNames.txt

PS C:\temp\workingDir> $len = $origin.length
PS C:\temp\workingDir> $out = for($idx=0; $idx -lt $len; $idx++) { "{0}|{1}" -f $orign[$idx], $wanted[$idx] }

PS C:\temp\workingDir> $out |out-file .\merged.txt


Results in merged.txt
A.png|x.png
B.png|y.png
C.png|z.png

Now use merged.txt for BRUs "Renaming From A Text File"

Warning: this is no copy and paste solution. Rather try to understand and write it yourself into the PS console. And,... be sure to adjust the paths and names as needed.




##############################


Create many copies from one source file

With a DOS batch: CopyOneToMany.cmd
Code: Select all
    @ECHO OFF
    CD %~dp0

    SET base=TheNameOfTheSourceFile
    SET exte=png

    ECHO copy one file to many; StS 2012
    ECHO working, please wait...

    setLocal EnableDelayedExpansion

    REM : from 1, step 1, up to 1000, do
    for /L %%D in (1,1,1000) DO (
        SET digit=0000%%D
          SET digit=!digit:~-4!
              copy  %base%.%exte% %base%_!digit!.%exte% >NUL
      )

    ECHO. & ECHO All done! & PAUSE



With PowerShell:
for($index=1; $index -lt 1001; $index++) {       $CopyPattern = "TheNameOfTheSourceFile_{0:D4}.png" -f $index;         copy  TheNameOfTheSourceFile.png   $CopyPattern;         }

or
for($index=1; $index -le 1000; $index++){       copy TheNameOfTheSourceFile.wav    ("TheNameOfTheSourceFile_{0:D4}.wav" -f $index)    }


Results in
TheNameOfTheSourceFile_0001.png
TheNameOfTheSourceFile_0002.png
TheNameOfTheSourceFile_0003.png
...




HTH? :D
Last edited by Stefan on Mon Jan 06, 2014 10:19 am, edited 6 times in total.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Copy name of one file to another (with different extension)

Postby yarali46 » Sun Jan 08, 2012 6:32 pm

Hi,

Thanks for the reply. I already know about the method you suggested. actually i can do the same without using BRU. i prepare a similar file like this:

ren filenameold1.srt filenamenew1.srt
ren filenameold2.srt filenamenew2.srt

save it as an ms-dos batch file (.bat extension). and run it. that's simple. but preparations take time...

i was asking for an easier was from BRU.

Thanks anyway.
yarali46
 
Posts: 2
Joined: Tue Jan 03, 2012 10:00 pm

Re: Copy name of one file to another (with different extension)

Postby bitmonger » Sat Jan 28, 2012 7:06 pm

Maybe I'm missing something, but wouldn't the simplest method to solve this be a simple replace? (That is assuming the example given actually represents the real filename)

For example, to convert:
TVSeries Season1-Episode01.srt
to
TV.Series.SE01.E01.srt

replace
Season (and space before it) with .SE0
and replace
-Episode with E

In BRU it would be something like
Regex(1)
Match
^(.+) Season(\d)-Episode(.+)
Replace
\1.S0\2E\3
Include Ext. not checked

If the season number ranged from single to double digits, do 2 passes; the first looking for Season\d\d and replace with S\d\d, the second look for Season\d-, replace with S0\d.

Using the examples given it would automatically only match files with the .srt extension and shorten them to match
the .avi names.
Worked for me
bitmonger
 
Posts: 50
Joined: Sat Sep 22, 2007 5:05 am


Return to Suggestions