0

我继承了以下脚本,它基本上只是查看文件夹,单独处理文件,然后移动它们并写入日志。

我当前面临的问题是,如果文件夹为空,脚本仍会创建一个处理文件夹以将潜在文件移动到其中,并写入日志。谁能帮我修改脚本,这样如果文件夹中没有文件就不会发生任何事情?我知道我需要在脚本顶部进行检查,如果没有文件则退出,但我没有批处理文件的经验,我不知道如何完成。

@ECHO OFF

set "folder=%~1"


::HERE I NEED ADD A CHECK TO SEE IF FILES EXIST.  IF THEY DO, GO THROUGH SCRIPT.  
::IF NOT, EXIT EVERYTHING

:: Set timestamp for processed folders
set TIMESTAMP=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%-         %TIME:~0,2%.%TIME:~3,2%.%TIME:~6,2%.%TIME:~9,2%

:: If more than 0 files exist begin ftp and file archival otherwise exit
FOR %%a IN (c:\Encoded_HL7_Vanderbilt\*.*) DO (

cd\"Program Files (x86)\Ipswitch\WS_FTP 12"
IF ERRORLEVEL 1 (echo %TIMESTAMP% Error switching to ftp program     directory>E:\HL7_Vanderbilt_log\%folder%\%TIMESTAMP%.error.txt
goto :done)

wsftppro -s local:%%a -d Vandy!Vanderbilt:/incoming/ 
IF ERRORLEVEL 1 (echo %TIMESTAMP% Error transmitting "%%a" file to ftp     server>E:\HL7_Vanderbilt_log\%folder%\%TIMESTAMP%.error.txt
goto :done)

md "E:\Processed_HL7_Vanderbilt\%folder%\%TIMESTAMP%" 2>nul
IF ERRORLEVEL 1 (echo %TIMESTAMP% Error creating archive     directory>E:\HL7_Vanderbilt_log\%folder%\%TIMESTAMP%.error.txt
goto :done)


move "%%a" "E:\Processed_HL7_Vanderbilt\%folder%\%TIMESTAMP%"
IF ERRORLEVEL 1 (echo %TIMESTAMP% Error moving "%%a" file to archive         directory>E:\HL7_Vanderbilt_log\%folder%\%TIMESTAMP%.error.txt
goto :done)

)

echo %TIMESTAMP% File transfers completed successfully or no files were         found>E:\HL7_Vanderbilt_log\%folder%\%TIMESTAMP%.success.txt
exit

:done 
goto :EOF
4

1 回答 1

1
dir "%~1" /a:-d /b >nul 2>&1
if %errorlevel%==1 exit

开始

于 2013-10-01T20:42:43.157 回答