【问题标题】:Passing a Date from an SSIS Package to a "Add Date Suffix to File Name" batch file routine将日期从 SSIS 包传递到“将日期后缀添加到文件名”批处理文件例程
【发布时间】: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


    【解决方案1】:

    由于 SSIS 比批处理文件少一点,另一个选择是让包在月份中使用前导零来格式化日期:

    Right("0"+ (DT_WSTR, 2) MONTH( @[User::ReportingMonth]  ) ,2) + "/" + Right("0"+ (DT_WSTR, 2) DAY( @[User::ReportingMonth]  ) ,2) + "/" + (DT_WSTR, 4) YEAR( @[User::ReportingMonth]  )  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-09
      • 1970-01-01
      • 2015-05-08
      相关资源
      最近更新 更多