Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Rename files from a string in random places from a text file  (Read 3450 times)

0 Members and 1 Guest are viewing this topic.

tlm2408

    Topic Starter


    Newbie

    • Experience: Familiar
    • OS: Windows 8
    I am trying to rename a bunch of .m3u files based on the text between ", and (s. The text might contain characters including
    Code: [Select]
    & (random text) . : ! | -
    So I need to remove the colon and the pipe. There is also white space before and after that I'd like to remove.

    Here are two examples

    in channel1.m3u

    Code: [Select]
    #EXTINF:-1 group-title="Documenteries" logo="/img/icon.png",: Animal Planet   (s-6)
    http://*********.m3u8

    in channel2.m3u

    Code: [Select]
    #EXTINF:-1 group-title="Misc" logo="/img/icon.gif", PAC-12 Net. (Bay Area) 1080P   (s-8)
        http://*********.m3u8

    Here is the batch file I have so far

    Code: [Select]
    @echo off
    cd Renamed_Files
    for /f "delims=" %%i in ('dir /a-d/b *.m3u') do (
       set "nname="
       set "fname=%%~i"
       for /f "tokens=* delims=,(" %%f in ("%%~i") do if not defined nname set "nname=%%f"
       setlocal enabledelayedexpansion

       echo rename "!fname!" "!nname!.m3u"
       endlocal
    )
    pause
    This gives me everything before the comma. If I change delims=,( to delims=( it gives me everything up to the Bracket, so I get the text I'm after, but I get all the text before it as well. The characters before the text I want are always ", and the characters after are always (s- if that helps.

    This could be either a batch file or vbscript. Any help would be greatly appreciated.