On Windows Server (Data Center? 2008?), i'm trying to set up a scheduled task that will:
- Within a particular directory
- For every file in it
- 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
Best Answer
here is the way to do it in powershell. Save as a .ps1 file. Set execution to remotesigned from powershell prompt (launch with run as administrator):
Set-ExecutionPolicy RemoteSigned
I created and tested this script for you based on what you asked
You need then to create a scheduled task that call powershell.exe with the script as argument