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

Author Topic: Topic: Batch file to rename basted on other filename before move new dest.  (Read 7051 times)

0 Members and 1 Guest are viewing this topic.

Rooki2020

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 8
    Like to change my Batch file from rename/stripping filename (today below) to copy the filename complete from an existing movie file (which can be .avi, .mov, .mp4) which always get dropped as pair in a folder under “Temp” before I move the JPEG-file away.

    @echo off
    setlocal enabledelayedexpansion
    set "sourcepath=C:\Temp"
    set "folderpath=C:\master"

    cd /d %sourcepath%
    for /f %%a in ('dir /b "*.jpg"') do (
        set "fname=%%~na"
        ren "%%a" "!fname:~0,-9!.jpg"
    )

    for /F "delims=" %%a in ('dir /b /od "%sourcepath%\*.jpg"') do (
       set "youngest=%%a"
       move /y "%sourcepath%\!youngest!" "%folderpath%"
    )
    endlocal

    Example could be:
    C:\Temp\name1
    09010203.mp4 and test.jpg, where the JPEG should change filename to 09010203.jpg, before I move it.