1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Need help batch renaming video files in a specific format

Discussion in 'DOS/Other' started by Shiken, Dec 27, 2012.

Thread Status:
Not open for further replies.
  1. Shiken

    Shiken Thread Starter

    Joined:
    Dec 27, 2012
    Messages:
    1
    I am working on renaming files that come from digital camera video recordings. They output files in a generic incremental filename of which I do not need any information from. My folder structure is:
    Code:
    x:\processing\01020304\VIDEO\0001.avi
    The filename I am trying to achieve would be for this example:

    Code:
    01-02-20121227-07h30m00s-03-04.avi
    In this example, 01-02 is the first 4 numbers of the \01020304\ folder. 20121227 is the date the video was created, with 07h30m00s as the ending time of the video, which is usually reported by the "last modified time". finally the 03-04 is the second half of the folder name used previously.

    I'm a complete novice to writing batch files like this, but was unable to find any other examples similar enough to get myself started, so any help would be greatly appreciated.

    Edit:
    So far, I've found / put this together, but it currently only works for the folder manually set. need to figure out a loop of sorts to check all subfolders of \processing\.
    Code:
    @echo off
    setlocal EnableExtensions EnableDelayedExpansion
    
    :: Setup
    rd /Q "%Temp%\Temp" & mkdir "%Temp%\Temp" 2>nul
    set "xPath=c:\processing\01010101\VIDEO"
    set "xFolder="
    
    :: Parse Folder Name
    for /f "tokens=3 delims=\" %%A in ("%xPath%") do set "xFolder=%%A"
    
    :: Loop through Videos
    pushd %xPath%
    for /f "tokens=1,2,3,4,*" %%A in ('dir *.avi /T:W /4') do if exist "%%~fE" (
        set "xDateWritten=%%~tE"
        set "xDateCreated=%%~A %%~B %%~C"
        set "xDateGMT=0000000000000000000"
        for /f "tokens=1,2" %%X in ('robocopy . "%Temp%\Temp" "%%~E" /TS /FP /NS /NC 
    
    /NP /NJH /NJS /NDL /L') do set "xDateGMT=%%X %%Y"
        echo %xFolder:~0,2%-%xFolder:~2,2%-!xDateCreated:~6,4!!xDateCreated:~0,2!!
    
    xDateCreated:~3,2!-!xDateWritten:~11,2!h-!xDateWritten:~14,2!m-!xDateGMT:~17,2!s-%
    
    xFolder:~4,2%-%xFolder:~6,2%%%~xE
    )
    popd
    
    endlocal
    pause
    EDIT2: resolved at stack overflow. end result:
    Code:
    @echo off
    setlocal EnableExtensions EnableDelayedExpansion
    
    :: Create Empty Folder
    rd /Q "%Temp%\Temp" 2>nul & mkdir "%Temp%\Temp"
    
    :: Loop through Folders
    pushd "xPath=c:\processing"
    for /d %%D in (*) do call :Process "%%~fD"
    popd
    goto End
    
    
    ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :Process <Parent>
    :: Folder Name
    set "xFolder=%~nx1"
    
    :: Set Sub Folder
    if not exist "%~1\VIDEO\" goto :eof
    pushd "%~1\VIDEO"
    
    :: Loop through Videos
    for /f "delims=" %%A in ('dir *.avi /b') do if exist "%%~fA" (
        set "xDateWritten=%%~tA"
        set "xDateGMT=0000/00/00 00:00:00"
        for /f "tokens=1,2" %%X in ('robocopy . "%Temp%\Temp" "%%~nxA" /TS /FP /NS /NC 
    
    /NP /NJH /NJS /NDL /L') do set "xDateGMT=%%X %%Y"
        rem Format = FF-FF-YYYYMMDD-HHh-MMm-SSs-FF-FF.ext
        echo %xFolder:~0,2%-%xFolder:~2,2%-!xDateWritten:~6,4!!xDateWritten:~0,2!!
    
    xDateWritten:~3,2!-!xDateWritten:~11,2!h-!xDateWritten:~14,2!m-!xDateGMT:~17,2!s-%
    
    xFolder:~4,2%-%xFolder:~6,2%%%~xA
    )
    popd
    goto :eof
    
    
    :End
    endlocal
    pause
    
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1082585

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice