Scheduled service/script/batch file to move files on condition of other files with similar filenames in same directory on windows

Posted by ilasno on Server Fault See other posts from Server Fault or by ilasno
Published on 2012-03-21T23:19:32Z Indexed on 2012/03/21 23:31 UTC
Read the original article Hit count: 263

On Windows Server (Data Center? 2008?), i'm trying to set up a scheduled task that will:

  1. Within a particular directory
  2. For every file in it
  3. If there exists (in the same directory) 2 files with similar names (actually the same name with extra extensions tagged on, ie. 'file1.mov' would need both 'file1.mov.flv' AND 'file1.mov.mpg' to exist), then move the file to another directory on a different disk.

Following is what i have so far for a batch file, but i'm struggling. I'm also open to another technique/mechanism.

@setlocal enableextensions enabledelayedexpansion
@echo off

SET MoveToDirectory=M:\_SourceVideosFromProduction
ECHO MoveToDirectory=%MoveToDirectory%
pause
for /r %%i in (*) do (

    REM ECHO %%i
    REM ECHO %%~nxi
    REM ECHO %%~ni
    REM ECHO filename=%filename%

    REM SET CurrentFilename=%%~ni
    REM ECHO CurrentFilename=%CurrentFilename%

    IF NOT %%~ni==__MoveSourceFiles (
        IF NOT x%%%~ni:\.=%==x%%%~ni% DO (
        REM SET HasDot=0

        REM FOR /F %%g IN %filename% do (
        REM     IF %%g==. (
                ECHO %filename%
        REM )
        )
    )
)

pause

© Server Fault or respective owner

Related posts about Windows

Related posts about windows-server-2008