- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个名为“Data”的文件夹,其中包含文件名中具有当前日期的所有文件,例如“myfile 20-08-2011”。现在我想创建一个 SSIS收集 08 月所有文件的包,也就是说,我想按月整理文件并将这些文件复制到一个名为“八月”的新文件夹中。我怎样才能做到这一点?
最佳答案
这是在 Foreach loop container
的帮助下实现此目标的一种可能解决方案, Script Task
和 File System Task
.您可以在没有文件系统任务的情况下执行此操作。但是,我已经使用它来利用内置的控制流任务来移动文件。该示例是使用 创建的SSIS 2005
.
该示例假定文件将被统一命名。因此,该示例使用格式 文件 DD-MM-YYYY .例如,文件将被命名为 File 29-07-2011
, File 15-08-2011
等等。
在 SSIS 包上,创建以下变量。在此示例中,源文件存储在文件夹位置 F:\Temp\
中。并且文件应该移动到位置 *F:\Temp\Monthwise*。在目标文件夹中,每个月都会有文件夹,例如 7 月、8 月等。
F:\Temp\Monthwise\August
但是这个变量将被分配到脚本任务中的实际值。现在,让我们分配值 F:\Temp\Monthwise\
.这个临时值是为了避免文件系统任务在设计时抛出错误消息。 F:\Temp\
F:\Temp\1.txt
. *.*
,这意味着所有文件都将被循环。您也可以指定 *.txt
或 File*.txt
或 My*.xls
等等,这取决于您的要求。 File 29-07-2011
, 07 月从第 9 个字符开始。因此值为 9。Foreach loop container
并将其配置为循环遍历变量
SourceFolder
中指定的文件夹使用文件模式变量
FilePattern
.当 Foreach 循环容器遍历文件时,文件名将分配给变量 SourceFilePath。我们将使用这个变量来获取脚本任务中的月份值。
Script Task
并在脚本任务的脚本部分单击设计脚本...按钮以打开 VSTA 编辑器并粘贴这些屏幕截图后提供的代码。由于示例是在 VS 2005 中创建的,因此代码是在
中编写的。 VB.NET 因为这是
SSIS 2005
中唯一支持的语言.
SourceFilePath
中获取完整的文件路径值。并仅提取文件名以将其存储在局部变量
FileName
中.
MonthStartPosition
和
MonthLength
变量分配有适当的非零值。然后提取月份值并将其存储在局部变量
MonthValue
中。 .
MonthValue
,它使用 DateTime 函数获取完整的月份名称值。值 1 分配给日和年,因为我们只需要月份名称。
DestinationFolder
.该变量将用于文件系统任务。
VB.NET code for SSIS 2005
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Dim varCollection As Variables = Nothing
Dts.VariableDispenser.LockForRead("User::SourceFilePath")
Dts.VariableDispenser.LockForRead("User::DestinationRoot")
Dts.VariableDispenser.LockForRead("User::MonthStartPosition")
Dts.VariableDispenser.LockForRead("User::MonthLength")
Dts.VariableDispenser.LockForRead("User::MonthNameFormat")
Dts.VariableDispenser.LockForWrite("User::DestinationFolder")
Dts.VariableDispenser.GetVariables(varCollection)
Dim SourceFilePath As String = varCollection("User::SourceFilePath").Value.ToString()
Dim FileName As String = SourceFilePath.Substring(SourceFilePath.LastIndexOf("\") + 1)
Dim DestinationRoot As String = varCollection("User::DestinationRoot").Value.ToString()
Dim MonthStartPosition As Integer = Convert.ToInt32(varCollection("User::MonthStartPosition").Value)
Dim MonthLength As Integer = Convert.ToInt32(varCollection("User::MonthLength").Value)
Dim MonthValue As Integer = 0
Dim MonthNameFormat As String = varCollection("User::MonthNameFormat").Value.ToString()
Dim FolderName As String = String.Empty
Dim MonthwiseDirectory As String = String.Empty
If MonthStartPosition > 0 AndAlso MonthLength > 0 Then
MonthValue = Convert.ToInt32(FileName.Substring(MonthStartPosition - 1, MonthLength))
End If
If FileName.Length > 0 AndAlso MonthValue > 0 Then
FolderName = New DateTime(1, MonthValue, 1).ToString(MonthNameFormat)
End If
MonthwiseDirectory = System.IO.Path.Combine(DestinationRoot, FolderName)
If Not System.IO.Directory.Exists(MonthwiseDirectory) Then
System.IO.Directory.CreateDirectory(MonthwiseDirectory)
End If
varCollection("User::DestinationFolder").Value = MonthwiseDirectory
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
C# code for SSIS 2008 and above
public void Main()
{
Variables varCollection = null;
Dts.VariableDispenser.LockForRead("User::SourceFilePath");
Dts.VariableDispenser.LockForRead("User::DestinationRoot");
Dts.VariableDispenser.LockForRead("User::MonthStartPosition");
Dts.VariableDispenser.LockForRead("User::MonthLength");
Dts.VariableDispenser.LockForRead("User::MonthNameFormat");
Dts.VariableDispenser.LockForWrite("User::DestinationFolder");
Dts.VariableDispenser.GetVariables(ref varCollection);
string SourceFilePath = varCollection["User::SourceFilePath"].Value.ToString();
string FileName = SourceFilePath.Substring(SourceFilePath.LastIndexOf('\\') + 1);
string DestinationRoot = varCollection["User::DestinationRoot"].Value.ToString();
int MonthStartPosition = Convert.ToInt32(varCollection["User::MonthStartPosition"].Value);
int MonthLength = Convert.ToInt32(varCollection["User::MonthLength"].Value);
int MonthValue = 0;
string MonthNameFormat = varCollection["User::MonthNameFormat"].Value.ToString();
string FolderName = string.Empty;
string MonthwiseDirectory = string.Empty;
if (MonthStartPosition > 0 && MonthLength > 0)
{
MonthValue = Convert.ToInt32(FileName.Substring(MonthStartPosition - 1, MonthLength));
}
if (FileName.Length > 0 && MonthValue > 0)
{
FolderName = new DateTime(1, MonthValue, 1).ToString(MonthNameFormat);
}
MonthwiseDirectory = System.IO.Path.Combine(DestinationRoot, FolderName);
if (!System.IO.Directory.Exists(MonthwiseDirectory))
{
System.IO.Directory.CreateDirectory(MonthwiseDirectory);
}
varCollection["User::DestinationFolder"].Value = MonthwiseDirectory;
Dts.TaskResult = (int)ScriptResults.Success;
}
关于ssis - 如何创建一个包,将给定文件夹中的所有文件复制到新文件夹中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7139172/
在下面的代码中,我得到一个 uninitialized value警告,但仅限于第二个 given/when例子。为什么是这样? #!/usr/bin/env perl use warnings; u
整个“开关”功能是否已成为实验性的?在没有 Perl 的 future 版本破坏我的代码的情况下,我可以依赖其中的某些部分吗?一般来说,将稳定功能更改为实验性的政策是什么? 背景use feature
有没有办法在一个条件语句中写出如下语句? a和b不能同时等于5。 (a可以是5,b可以是5,但是a AND b不能是5) 最佳答案 正如克里斯指出的那样,您要查找的是逻辑异或,相当于逻辑不等于 !=:
我正在寻找一种算法来找到给定 n 条线段的所有交点。以下是来自 http://jeffe.cs.illinois.edu/teaching/373/notes/x06-sweepline.pdf 的伪
数组中有 N 个元素。我可以选择第一项最多 N 次,第二项最多选择 N-1 次,依此类推。 我有 K 个 token 要使用并且需要使用它们以便我可以拥有最大数量的项目。 arr = [3, 4, 8
我正在尝试修复法语文本中的语法性别,想知道是否有办法从某个词条中获取所有单词的列表,以及是否可以在此类列表中进行查找? 最佳答案 尝试: import spacy lemma_lookup = spa
我正在为 Win32 编写一个简单的自动化测试应用程序。它作为一个单独的进程运行,并通过 Windows API 访问目标应用程序。我可以阅读窗口层次结构,查找标签和文本框,并通过发送/发布消息等来单
在 nodeJs 中使用 Sequelize 时,我从 Sequelize 收到此错误,如下所示: { [SequelizeUniqueConstraintError: Validation erro
本文https://arxiv.org/pdf/1703.10757.pdf使用回归激活映射 (RAM) - 而不是类激活映射 (CAM) 来解决问题。有几篇文章描述了如何实现 CAM。但是我找不到
我正在研究 Mach 动态链接器 dyld。这个问题适用于所有 Apple 平台,但很高兴得到特定于平台的答案;我正在使用 ObjC,但如果对你有用的话,我也很乐意翻译 Swift。 The rele
我有一个包含数千个 Instagram 用户 ID 的列表。我如何获得他们的 Instagram 用户名/句柄? 最佳答案 你必须使用这个 Instagram API: https://api.ins
我在下面的代码: def main(args: Array[String]) { val sparkConf = new SparkConf().setAppName("Spark-Hbase").s
我有一个表格,其中包含从 1 到 10 的数字。(从 D2 到 M2) 假设A1中有03/09/2019 并且在B1中有06/09/2019 并且在C1中有Hello 在A 列中,我有多个系列的单词,
我想在给定服务对应的 URI 的情况下检索服务的注释(特别是 @RolesAllowed )。这是一个例子: 服务: @GET @Path("/example") @RolesAllowed({ "B
我看到 OraclePreparedStatementexecuteQuery() 表现出序列化。也就是说,我想使用相同的连接对 Oracle 数据库同时运行两个查询。然而,OraclePrepare
import java.util.Scanner; public class GeometricSumFromK { public static int geometricSum(int k,
我创建了一个抽象基类Page,它说明了如何构建动态网页。我正在尝试想出一种基于作为 HttpServletRequest 传入的 GET 请求生成 Page 的好方法。例如... public cla
我的字符串是一条短信,采用以下两种格式之一: 潜在客户短信: 您已收到 1 条线索 标题:我的领导 潜在客户 ID:12345-2365 警报设置 ID:890 短信回复: 您已收到 1 条回复 标题
我在 python 中有以下代码: class CreateMap: def changeme(listOne, lisrTwo, listThree, listFour, listfive):
这是在 Hibernate 上运行的 JPA2。 我想检索相同实体类型的多个实例,给定它们的 ID。其中许多已经在持久性上下文和/或二级缓存中。 我尝试了几种方法,但似乎都有其缺点: 当我使用 ent
我是一名优秀的程序员,十分优秀!