如何在不指定文件名的情况下仅获取.zip文件 [英] How do i get only .zip files without specifying the file name

查看:122
本文介绍了如何在不指定文件名的情况下仅获取.zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码只有当我在路径中写入整个文件名和.zip扩展名(粗体和下划线部分)时才能工作,而我面临的问题是文件名的变化。那么我如何只获取.zip文件而不指定文件夹中的文件名?请帮助



Hi, the code below works BUT only when i write the entire filename and .zip extension in the path (Bold & underlined section) and the problem im facing is that filenames somtimes change. so how do i get only .zip files without specifying the file name in a folder? Please help

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

<microsoft.sqlserver.dts.tasks.scripttask.ssisscripttaskentrypointattribute> _
<system.clscompliantattribute(false)> _
Partial Public Class ScriptMain
       Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

       Enum ScriptResults
             Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
             Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
       End Enum
    Public Sub Main()
        Try
            'Create the connection to the ftp server
            Dim cm As ConnectionManager = Dts.Connections.Add("FTP")
            'Set the properties like username & password
            cm.Properties("ServerName").SetValue(cm, "\")
            cm.Properties("ServerUserName").SetValue(cm, "")
            cm.Properties("ServerPassword").SetValue(cm, "")
            cm.Properties("ServerPort").SetValue(cm, "")
            cm.Properties("Timeout").SetValue(cm, "0") 'The 0 setting will make it not timeout
            cm.Properties("ChunkSize").SetValue(cm, "1") '1000 kb
            cm.Properties("Retries").SetValue(cm, "")
            'create the FTP object that sends the files and pass it the connection created above.
           Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))
            'Connects to the ftp server
            ftp.Connect()
            'Build a array of all the file names that is going to be FTP'ed (in this case only one file)
            Dim files(0) As String



files(0)=K:\SISS \ file2.zip



''ftp文件

''注意:我很难过找到远程路径目录。我通过在SSIS包中创建FTP连接和任务错误地发现了它,并且它默认了FTP任务中的远程路径设置。

ftp.SendFiles(files,/ FtpRainbow,True, False)''True使它覆盖现有文件,False表示它不传输ASCII


files(0) = "K:\SISS\file2.zip"

''ftp the file
''Note: I had a hard time finding the remote path directory. I found it by mistake by creating both the FTP connection and task in the SSIS package and it defaulted the remote path setting in the FTP task.
ftp.SendFiles(files, "/FtpRainbow", True, False) '' the True makes it overwrite existing file and False is saying that it is not transferring ASCII

ftp.Close()
       Catch ex As Exception
           Dts.TaskResult = ScriptResults.Failure
       End Try
       Dts.TaskResult = ScriptResults.Success

   End Sub

推荐答案

使用类似下面的内容来获取文件名...

Use something similar to the following to get the filename ...
Dim d As DirectoryInfo = New DirectoryInfo("c:\\")
Dim f As FileInfo() = d.GetFiles("*.zip")
files(0) = f(0).Name 'actually you don't need the files array just keeping your variable name for illustration


这篇关于如何在不指定文件名的情况下仅获取.zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆