【发布时间】:2011-09-16 11:49:42
【问题描述】:
我有一个 SSIS 包,它将日期参数从包变量传递到批处理文件作为参数。批处理文件的目的是在预定位置重命名预定文件,例如将日期后缀添加到文件名中,其中日期后缀的格式为“_YYYY_MM”。
我遇到的问题是,当我在 IDE 中运行 SSIS BIDS 2005 包时,以下批处理文件重命名了该文件,该文件没有前导零。但是,当我通过测试服务器上的调度程序运行它时,该文件被正确重命名,因此月份有一个前导零。
可能是由于驱动程序的潜在差异?
这是批处理文件的代码:
ECHO OFF
SET CurrentFolder=%~dp0
SET ThisFileName=%~n0
REM The following line populates shared path variables used below
CALL %CurrentFolder%\Membob_SetPaths.cmd
SET LogFile=%LogFolder%\%ThisFileName%.log
ECHO %date% %time% - *** BOJ %CurrentFolder%%ThisFileName%.cmd *** >> %LogFile%
SET ReportingDate=%1
ECHO Logging to: %LogFile%
ECHO ReportingDate=%ReportingDate% >> %LogFile%
REM Rename the file from MEMBOB.csv to MEMBOB_YYYY_MM.csv, using the passed ReportingDate
REM But before we rename, delete any file that might already have that target name.
@For /F "tokens=1,2,3 delims=/ " %%A in ("%ReportingDate%") do @(
Set Month=%%A
Set Day=%%B
Set Year=%%C
)
REM if %Month% LSS 10 Set Month=0%Month%
SET NewFileName=MEMBOB_%Year%_%Month%.csv
if exist %ExportFolder%\%NewFileName% del %ExportFolder%\%NewFileName%
REM Rename the file as described above
ECHO Rename %ExportFolder%\Membob.csv to %NewFileName% >> %LogFile%
rename %ExportFolder%\Membob.csv %NewFileName%
ECHO %date% %time% - *** EOJ %CurrentFolder%%ThisFileName%.cmd *** >> %LogFile%
我真的是批处理文件的菜鸟。
如果有人可以提供帮助,我想做的是:
如果作为字符串计算的月份长度为
其次,我希望这个重命名文件过程更通用,以便我可以将文件名完整路径作为附加参数传递,并在任何文件上添加后缀。
有更多 BATCH 能力的人可以提供帮助吗?
【问题讨论】:
标签: batch-file ssis-2005