精华内容
下载资源
问答
  • VB读取文件名.

    2011-06-30 18:57:56
    VB读取指定文件夹下的所有文件的名字以及属性
  • Private Sub ExportCostSheetData() InsertRow("") InsertRow("Run 2:Export CostingSheet=========================") InsertRow("Status:System Connectting DataBase!") I...
    Private Sub ExportCostSheetData()
            InsertRow("")
            InsertRow("Run 2:Export CostingSheet=========================")
            InsertRow("Status:System Connectting DataBase!")
            If ConnJWeb() = False Or ConnJWeb2() = False Then
                InsertRow("Status:System Connectting DataBase fialed!")
                AddRow("", "", "Status:System Connectting DataBase fialed!", "system")
                Exit Sub
                ' GoTo End1
            End If
            Dim CurrentComp As Integer
            Dim strDestFolder As String = "\\1.1.1.1\BogartCosting\CostSheet\"
            Dim rsR As New ADODB.Recordset
            Dim Flag As String = selectValue(" select top 1 flag from CostingSheetFileInfo ", adoJWeb, 0)
            Try
    
                Dim strFiles() As String = Directory.GetFiles(strDestFolder)
                Dim strFile As String
                Dim AbsolutePath As String
                Dim strFilePresent As String
    
                rsR.Open("select * from CostingSheetFileInfo ", adoJWeb, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
                For Each strFile In strFiles
                    strFilePresent = Path.GetFileName(strFile)
                    AbsolutePath = strDestFolder & strFilePresent
                    Dim netCmd As New OleDb.OleDbCommand("P_DeleteRecord", netJWeb)
                    netCmd.CommandType = CommandType.StoredProcedure
                    netCmd.Parameters.Add("@FileName", strFilePresent)
                    netCmd.Parameters.Add("@FileType", "Complete Costing")
                    netCmd.ExecuteNonQuery()
                    rsR.AddNew()
                    rsR.Fields("FileName").Value = strFilePresent
                    rsR.Fields("FileType").Value = "Complete Costing"
                    rsR.Fields("AbsolutePath").Value = AbsolutePath
                    rsR.Fields("LastUpdateDate").Value = Now()
                    rsR.Fields("Flag").Value = IIf(Flag = 0, "1", "0")
                    rsR.Update()
                    InsertRow(strFilePresent & "===OK!")
                    CurrentComp = CurrentComp + 1
                    Me.ProgressBar1.Value = (CurrentComp / strFiles.Length) * 100
                Next
                rsR.Close()
            Catch ex As Exception
                SendEmail()
                InsertRow("===Open Folder Fail===")
                InsertRow("End Time:" & Now)
                Exit Sub
            End Try
    
    
            adoJWeb.Execute("Update CostingSheetFileInfo set flag='" & IIf(Flag = 0, "1", "0") & "' where flag is null ")
            adoJWeb.Execute(" delete from CostingSheetFileInfo where flag='" & Flag & "'")
            '  InsertRow(" Total error records:" & strFiles.r & "")
            InsertRow("")
            InsertRow("***************** System export result *******************")
    
            InsertRow("")
            InsertRow("End Time:" & Now)
            InsertRow("***************************************************************")
    
    
        End Sub

     

    转载于:https://www.cnblogs.com/vinsonLu/p/3464931.html

    展开全文
  • 如图N列是文件夹名,S列是文件名,文件位置是C:\Users\Administrator\Desktop\异形数据对接仁科\fic,文件后面的类型是mpr。然后要读取A列数据,如果是“异形面板_2_BBBBB“”则执行某项代码 最好是VB代码
  • VB.net TreeView 读取系统文件名

    千次阅读 2012-05-08 20:53:39
    Imports System.IO Imports System.Data 'Imports System.Data.Linq 'Imports System.Data.Linq.Mapping Imports System.Windows.Forms   ...Private Sub TreeView1_AfterSelect(ByVal sende

    Imports System.IO
    Imports System.Data
    'Imports System.Data.Linq
    'Imports System.Data.Linq.Mapping
    Imports System.Windows.Forms

     

    Public Class Form1

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
    If Not TreeView1.SelectedNode Is Nothing Then
     MessageBox.Show(TreeView1.SelectedNode.Text)
    End If

    End Sub

    Public Sub AddDirectory(ByVal strFatherPath As String, ByVal strPath As String, ByVal nodeFather As TreeNode)

      Dim iDir As IO.Directory

      Dim iDirInfo As IO.DirectoryInfo

      Dim i As Integer

      Dim node As New TreeNode

      '先添加本目录,从文件夹路径分析出文件夹名称

      node.Text = Strings.Replace(strPath, strFatherPath & "\", "", , 1)

      '为单个节点指定节点未被选中时显示的图标

      node.ImageIndex = 1

      '为单个节点指定节点被选中时显示的图标

      node.SelectedImageIndex = 2

      nodeFather.Nodes.Add(node)

      Application.DoEvents()

      Try

      Dim str() As String = IO.Directory.GetDirectories(strPath)

      '遍历该目录的子文件夹

      For i = 0 To str.GetUpperBound(0)

      AddDirectory(strPath, str(i), node)

      Next

      Catch ex As Exception

      Debug.WriteLine(ex.Message)

      End Try

      node = Nothing

      iDir = Nothing

      End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

      Dim iDir As IO.Directory

      Dim node As New TreeNode

      '先把C盘添加到树中

      TreeView1.Nodes.Clear()

      node.ImageIndex = 0

      node.Text = "PC_Code"

      node.SelectedImageIndex = -1

      TreeView1.Nodes.Add(node)

      Dim i As Integer

      '获取C:盘根目录下的文件夹

      Dim str() As String = IO.Directory.GetDirectories("F:\PC_Code")

      For i = 0 To str.GetUpperBound(0)

    '调用遍历过程

    AddDirectory("F:\PC_Code:", str(i), node)

      Next

      node = Nothing

      iDir = Nothing

      End Sub

        Function GetFiles(ByVal MyDir As String) As IEnumerable(Of System.IO.FileInfo)

    Dim Coll As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
      Coll = My.Computer.FileSystem.GetFiles("F:\PC_Code\1")
    Dim filename As String
      For Each filename In Coll
      Dim node As New TreeNode
      node.ImageIndex = 1
    Dim arr As String() = filename.Split("\")

     node.Text = arr(arr.Length - 1)

      TreeView1.Nodes.Add(node)

      Next

            If (Not System.IO.Directory.Exists(MyDir)) Then
                Throw New System.IO.DirectoryNotFoundException()
            End If
            Dim MyFileNames As String()
            Dim MyFiles As List(Of System.IO.FileInfo) = New List(Of System.IO.FileInfo)()

            MyFileNames = System.IO.Directory.GetFiles(MyDir)
            For Each MyName As String In MyFileNames
                MyFiles.Add(New System.IO.FileInfo(MyName))
            Next
            Return MyFiles
        End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim MyDir As String = "F:\PC_Code\1"
    Dim list As List(Of String) = New List(Of String)
            Dim MyFiles = GetFiles(MyDir)

            Dim MyStartDate As DateTime = Me.dateTimePicker1.Value
            Dim MyEndDate As DateTime = Me.dateTimePicker2.Value

    End Sub
    End Class

    展开全文
  • 一、以循环来读取Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click On Error Resume Next Dim s As String With OpenFileDialog1 
    一、以循环来读取
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            On Error Resume Next
            Dim s As String
            With OpenFileDialog1
                .Multiselect = True
                .FileName = ""
                .Filter = "Excel文件(*.xls)|*.xls"
                .FilterIndex = 1
            End With
            OpenFileDialog1.ShowDialog()
            For Each s In OpenFileDialog1.FileNames
                ListBox1.Items.Add(s)
            Next
    End Sub
     二、更简洁的方法
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            On Error Resume Next
           With OpenFileDialog1
                .Multiselect = True
                .FileName = ""
                .Filter = "Excel文件(*.xls)|*.xls"
                .FilterIndex = 1
           End With
           OpenFileDialog1.ShowDialog()
           ListBox1.Items.AddRange(OpenFileDialog1.FileNames)
    End Sub
    展开全文
  • 请问如何从OpenFileDialog中读取所有文件名到Listbox Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click On Error Resume Next With OpenFileDialog...
    VB.NET源码-156个实用实例哦……
    
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    
    请问如何从OpenFileDialog中读取所有文件名到Listbox
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    On Error Resume Next
    With OpenFileDialog1
    .Multiselect = True
    .FileName =
    .Filter = Excel文件(*.xls)|*.xls
    .FilterIndex = 1
    End With
    OpenFileDialog1.ShowDialog()
    ListBox1.Items.Add(OpenFileDialog1.FileName)
    End Sub

    请问如何从OpenFileDialog中读取所有文件名到Listbox?
    __________________________________________________________________________
    问题已经解决,不知是否正确?

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    On Error Resume Next
    Dim s As String
    With OpenFileDialog1
    .Multiselect = True
    .FileName =
    .Filter = Excel文件(*.xls)|*.xls
    .FilterIndex = 1
    End With
    OpenFileDialog1.ShowDialog()
    For Each s In OpenFileDialog1.FileNames
    ListBox1.Items.Add(s)
    Next
    End Sub
    __________________________________________________________________________
    那你用选取文件夹的方式好了。。。。

    FolderBrowserDialog:

    If Me.FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
    Me.ListBox1.DataSource = IO.Directory.GetFiles(Me.FolderBrowserDialog1.SelectedPath)
    End If
    __________________________________________________________________________
    en 可以这么解决
    __________________________________________________________________________
    With OpenFileDialog1
    .Multiselect = True
    .FileName =
    .Filter = Excel文件(*.xls)|*.xls
    .FilterIndex = 1
    End With
    OpenFileDialog1.ShowDialog()

    ListBox1.Items.AddRange(OpenFileDialog1.FileNames)
    __________________________________________________________________________
    不必用循环而用ListBox.Items.AddRanage就可以加一个集合进来了,如上.
    __________________________________________________________________________
    高手啊!
    佩服!
    __________________________________________________________________________
    感谢fangxinggood(JustACoder) 和平民百姓等高手!
    __________________________________________________________________________
    展开全文
  • VB读取目录、文件方法 方法一: Dir 与 MkDir Dir 函数 返回一个 String,用以表示一个文件名、目录名或文件夹名称,它必须与指定的模式或文件属性、或磁盘卷标相匹配。 语法 Dir[(pathname[, ...
  • vb读取txt文件到textbox (一) 2011年05月10日  1.怎么通过代码创建一个文本文件,并读取,更新内容  以上为随即方式打开的文本文件  dim gfilenum as integer  gfilenum = FreeFile  Open "文件...
  •  Files(a) = Path & sPath '将文件目录和文件名组合,并存放到数组中  List1.AddItem Files(a) '加入list控件中  sPath = Dir '查找下一个文件  DoEvents '让出控制权 Loop   sPath = Dir...
  • VB目录遍历读取源码示例,一个基础的FSO文件系统操作实例,直接读取所有的目录和子目录,可一级一级读取文件夹,直到无文件夹为止,然后读取最后一个目录中的所有文件,列出这些文件名。以截图示例的程序,将读取...
  • System.IO.Directory.GetFiles中的路径如果明确指定就可以,如果按照下面这种方法就不行,求大神指点 Private Sub Button5_Click(sender As Object, e As ... MsgBox("读取文件出错") End Try End Sub
  • VB操作ini文件的一个实例,包括了一个INI文件操作类,程序演示了读取和写入键值,包括以下功能:  可操作 Ini文件名和错误信息,对ini文件属性进行初始化、指定Ini文件名、向Ini文件中写入一个键值,如果键和...
  • 功能强大的硬盘信息读取程序VB源代码,可以获取硬盘型号、序列号、分区信息、每个分区的大小以及文件系统、簇信息、使用情况、硬盘特征信息等。另外程序还可以有很多设置选项:是否支持大小写敏感字符文件名、大小写...
  • 如何在VB读取 UTF-8 格式的文件?

    千次阅读 2008-05-20 13:34:00
    这个问题因扰了我很久,先在VB6 中测试多种方法,但都没有成功,最后先使用VB.Net 产生一个转换用的dll ,然后再在VB6 中调用此DLL, 以前是这样解决的。可以,有时也有问题,也是很笨的方法。最终找到一个很简单...
  • VB2005中,读取文本文件中的文本可以采用的方法是System.IO.File.ReadAllText,这个函数有两个参数,一个是文件的文件名(包含路径);一个是文本的编码,如果省略,采用系统默认的编码。可是,一般的文本编码有...
  • PublicFunctionGetImageFromFile()FunctionGetImageFromFile(ByValpstrFileNameAsString)AsBoolean DimstrExtAsString=""'扩展文件名 DimblnFlagAsBoolean=False I...
  • ''' ''' 创建XML文件 ''' ''' 要创建的XML文件名 ''' Private Sub createXML(ByVal xmlFileName As String) Try Dim writer As New Xml.XmlTextWriter(Application.StartupPath &
  • vb.net 创建、修改、读取XML的方法

    万次阅读 2008-03-05 09:33:00
    创建XML文件 要创建的XML文件名 Private Sub createXML()Sub createXML(ByVal xmlFileName As String) Try Dim writer As New Xml.XmlTextWriter(Application.S
  • VB随笔3

    2014-05-11 11:11:00
    1 读取文件内容 必须现在程序目录下(vb98文件夹下)建一个hero.txt Private Sub Command1_Click()Dim strfilename As String '文件名Dim nfilenum As Long '文件句柄Dim strall As String '所读取的文本文件的所有...
  • VB读写

    2009-04-05 10:22:00
    lof返回的是字节数 而VB的字符串是以一个UniCode字符作为单位 读取: Dim TempFile As Long Dim LoadBytes() As Byte TempFile=FreeFile Open 文件名 For Binary As #Tem
  • vb写的程序,读取excel,将修改的文件批量上传到vss,再获取当天要发布的文件名,批量从vss中获取,发布到指定的服务器目录。
  • vb6.0文件搜索查找程序实例,操作时选取文件夹所在的路径,选择文件所在范围,输入要查找的文件名进行搜索,调用SearchDirs函数查找文件,声明搜索文件要用到API函数和变量类型,递归调用Searchdirs自定义过程,实现...
  • vb.net 判断文件编码的方法

    千次阅读 2016-02-24 11:37:00
    vb.net 判断文件编码的三种方法 使用方法:GetEncoding(文件名) ' 读取文本文件的内容 ' ' 文件名 ' 文件编码 ' 文件内容  Public Function ReadFile(ByVal fileName As String) As String    If File....

空空如也

空空如也

1 2 3 4 5 6
收藏数 102
精华内容 40
关键字:

vb读取文件名