VB.net无法识别网络文件路径

时间:2014-12-01 16:11:44

标签: vb.net network-programming

问题:我有一个用户从手持刻录机上传口述。停靠时,文件从手机迁移到TEMP文件夹位置。从那里计算机上的软件将文件上传到服务器。出现问题时,文件将挂在TEMP位置。

解决方案:最初尝试复制文件(如果使用robocopy存在),但是,重复的名称和命名约定限制强制改变方法。我决定创建一个小程序来扫描域中所有PC上的文件目录。如果TEMP文件夹包含文件,则计算机名称的输出将显示在列表框中。 (我还没有设置解析来显示名称所以现在它显示了完整的文件路径。)

问题:我有错误检查,以验证文件路径是否存在但是是否为空,存在并包含文件,最后是否存在。问题是程序说每个文件目录“都不存在”。我已经验证了路径确实存在,并且我可以从启动Debug的同一台机器上取消UNC。我也测试过域管理员。我也试过在文件路径上包含和不包含引号(文件路径中有空格)。 HIGH和LOW字段是要扫描的最低和最高资产标签信息(设置要扫描的资产范围)。

代码(VB.Net 2010):

Imports System.IO

Public Class Main

    Private Sub btnScan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScan.Click
        Dim fs, oFolder
        Dim strFolderPath As String
        Dim count As Integer
        Dim low As Integer
        Dim high As Integer
        Dim company As String = "\\Company"
        Dim path As String = "\c$\Program Files\Speech Machines\SubSpace\temp"
        Dim countpath As String = ""
        lstNames.Items.Clear()
        low = CInt(txtLow.Text)
        high = CInt(txtHigh.Text)
        For count = low To high
            countpath = count.ToString
            fs = CreateObject("Scripting.FileSystemObject")
            strFolderPath = (Chr(34) + oah + countpath + path + Chr(34))
            If My.Computer.FileSystem.DirectoryExists(strFolderPath) Then
                oFolder = fs.GetFolder(strFolderPath)
                If (oFolder.files.count = 0) Then
                    'folder is Empty
                    lstNames.Items.Add(oah + countpath + " " + "Empty")
                Else
                    ' folder isn't empty
                    lstNames.Items.Add(oah + countpath + " " + "Files Contained: " & oFolder.files.count)
                End If
                fs = Nothing
            Else
                'folder does not exist
                lstNames.Items.Add(strFolderPath + " " + "Does not exist")
            End If
        Next
        'completion message
        MessageBox.Show("Scanning Complete")
    End Sub

    Private Sub SaveListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveListToolStripMenuItem.Click
        Dim sfd As New SaveFileDialog
        'Prompt the user for a file name to save to.
        If sfd.ShowDialog() = DialogResult.OK Then
            'Create the file to save to.
            Dim output As New IO.StreamWriter(sfd.FileName)
            'Write lines of text to the file.
            For Each item As Object In lstNames.Items
                output.WriteLine(lstNames.GetItemText(item))
            Next item
            'Close the file.
            output.Close()
        End If
    End Sub

End Class

0 个答案:

没有答案