ファイル名があるもので始まる場合はこのスクリプトで別のスクリプトを実行し、別のもので始まる場合は別のスクリプトを実行し、それ以外で始まる場合は残りのコードを続行したいと考えています。フォルダー内のすべてのファイルを反復処理し、これをチェックしたいと思います。私はしばらくそれに取り組んできましたが、どうやら適切に動作させることができないように見えるので、新鮮な目を探しています. どんな助けでも大歓迎です!
:========================================================================================
:: purpose: 1. copy file(s) from the export dir (SOURCE_DIR) (ARCHIVE_DIR)
:: 2. copy file(s) from the export dir (SOURCE_DIR) (TARGET_DIR)
:: 3. once file(s) are processed delete them from the export dir (SOURCE_DIR)
::=======================================================================================
::
@echo off
setlocal
:: Display the command line on the window's Title Bar
title %0 %1
set LOG_FILE="here.txt"
set SOURCE_DIR=here\there
set TARGET_DIR=here\nowHere
set ARCHIVE_DIR=here\oldStuffnThings
set FILE=FileStartingWithBlahBlergOrOther.docx
echo --------------------------------------------------------------------------------------------------------------------------------------- >> %LOG_FILE%
echo %DATE% %TIME% Starting file move >> %LOG_FILE%
if not exist "%SOURCE_DIR%%FILE%" (
echo %DATE% %TIME% "%SOURCE_DIR%%FILE%" not found >> %LOG_FILE%
echo %DATE% %TIME% no files to move so stopping >> %LOG_FILE%
exit
)
FOR /R %completepath% %%G IN (FileStartingWithBLAH*) DO (
call C:\otherScript1
)
FOR /R %completepath% %%G IN (FileStartingWithBLERG*) DO (
call C:\otherScript2
)
:: one at a time copy files to archive, copy to dir, then delete from the export dir
FOR /R %SOURCE_DIR% %%G IN (%FILE%) DO (
echo %DATE% %TIME% %%G was found for processing >> %LOG_FILE%
XCOPY %%G "%ARCHIVE_DIR%"/Y
echo %DATE% %TIME% %%G was archived status %ERRORLEVEL% >> %LOG_FILE%
XCOPY %%G "%TARGET_DIR%"/Y
echo %DATE% %TIME% %%G was copied to dir status %ERRORLEVEL% >> %LOG_FILE%
del %%G
echo %DATE% %TIME% %%G was deleted from the export dir status %ERRORLEVEL% >> %LOG_FILE%
)
rem set err_code=%errorlevel%
rem if %err_code% NEQ 0 (
rem echo %DATE% %TIME% **ERROR moving files %err_code% >> %LOG_FILE%
rem exit
rem )
rem echo %DATE% %TIME% File(s) moved successfully >> %LOG_FILE%
rem echo %DATE% %TIME% Process Complete >> %LOG_FILE%