如何在不指定文件名的情况下仅获取.zip文件

编程入门 行业动态 更新时间:2024-10-08 04:31:00
本文介绍了如何在不指定文件名的情况下仅获取.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文件

本文发布于:2023-11-01 01:04:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547795.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件名   情况下   文件   如何在   zip

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!