shell script - How to rename a movie file and also files ins subdirectories (e.g. subtitles) beginning with same prefix

07
2014-04
  • Kuddel

    I've several directories with movie files , and also subdirectories with subtitles files with same prefix or starting with same prefix.

    I want to rename subtitles files with the Directory name it is contained as shown in example.

    Example:

    Directory "My.favorite.Movie.1080p":
    abc-myfav-1080p.mkv
    Subs\abc-myfav-1080p.idx
    Subs\abc-myfav-1080p.sub
    Subs\abc-myfav-1080p-eng.idx
    Subs\abc-myfav-1080p-eng.sub
    Subs\abc-myfav-1080p-forced.idx
    Subs\abc-myfav-1080p-forced.sub
    

    they should be renamed to:

    Directory "My.favorite.Movie.1080p":
    My favorite Movie 1080p.mkv
    Subs\My favorite Movie 1080p.idx
    Subs\My favorite Movie 1080p.sub
    Subs\My favorite Movie 1080p-eng.idx
    Subs\My favorite Movie 1080p-eng.sub
    Subs\My favorite Movie 1080p-forced.idx
    Subs\My favorite Movie 1080p-forced.sub
    

    Does anybody can tell me a Windows Batch Script or a bash script (which i can apply by Mobaxterm)?

    Thanks in advance!

  • Answers
  • nonterrorist

    Bulk Rename Utility allows you to set up conditions for renaming a list of files. In this case, you can replace any instance of "abc-myfav-" with "My favorite Movie ".

    BRU

    You can also enable the subfolders checkbox to specify how far down you would like to rename. Allowing you to rename from the root directory down to the "Subs" folder in one shot.


  • Related Question

    windows xp - In XP, how do I rename a directory of files using a regex or similar to remove part of a filename and add a prefix?
  • jcolebrand

    I have a list of files generated from SSMS in XP like this:

    dbo.mysproc1.StoredProcedure.sql
    dbo.mysproc2.StoredProcedure.sql
    dbo.mySproc3.StoredProcedure.sql
    ... you get the drift
    

    I want to rename them to:

    proc.dbo.mysproc1.sql
    proc.dbo.mysproc2.sql
    proc.dbo.mySproc3.sql
    ... you get the drift
    

    I'm open to powershell, plain old batch, or whatever. If you can do it with a regex that would be fascinating, but whatever works there too. I want the ends, not the means, yeah? Just not sure what command to use. I do not, however, want to download a tool to do this. Native XP SP3 please.

    This is a one-off job, not something to be scripted, if that matters. But I may repeat it in the future, so scriptable is not a bad thing.


  • Related Answers
  • Ryan

    Put this in a batch file that's in the same directory and run:

    for /f "delims=. tokens=1,2,3,4" %%A IN ('dir /b *.sql') DO RENAME %%A.%%B.%%C.%%D proc.%%A.%%B.%%D
    

    That'll split the filename up by the "." character using the %%A through %%D variables, and then rename using the rearranged filename.

  • Nick T

    A crude PS script for kicks:

    gci | foreach { $f = $_; $split = $f.Name.Split("."); $n = [string]::join(".", "proc", $split[0], $split[1], "sql")); ren $f $n;}