0

如果文件名以一个东西开头,我想让这个脚本执行另一个脚本,如果它以另一个东西开头,另一个脚本,如果它以其他任何东西开头,则继续执行其余代码。我希望它遍历文件夹中的所有文件并对此进行检查。我已经研究了一段时间,并且正在寻找一双新的眼睛,因为显然我似乎无法让它正常工作。任何帮助,将不胜感激!

 :========================================================================================
:: 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%
4

1 回答 1

0

一个问题是你必须在后面加上一个反斜杠,SOURCE_DIR=here\there否则它会寻找here\thereFileStartingWithBlahBlergOrOther.docx

于 2013-02-03T06:04:23.390 回答