2

我被要求创建一个轮询活动目录的控制台应用程序。(C.\Temp\输入)

当文件带有 时(filename).SUCCESS,将检索文件名以运行 SQL 查询。所以

IF fileextension = SUCCESS

使用文件名运行 SQL 查询以更改 SQL 表中的值。将原始文件移动到c:\temp\Input\Processed

任何帮助或提示将不胜感激。

更新:

嗨,通过对各种网站的一些看法,我想出了以下内容。现在忘记 SQL,我只是在文件名和文件移动之后,但我得到一个文件已经在使用中的 IO 异常:

导入 System.IO 导入 System.String 模块 Module1

Dim fileName As String = "C:\temp\Input\NR12345.success"
Dim pathname As String = "C:\temp\Input\"
Dim result As String
Dim sourceDir As String = "C:\temp\Input\"
Dim processedDir As String = "C:\temp\Input\Processed\"
Dim fList As String() = Directory.GetFiles(sourceDir, "*.success")



Sub Main()
    result = Path.GetFileName(fileName)
    Console.WriteLine("GetFileName('{0}') returns '{1}'", fileName, result)
    result = Path.GetFileName(pathname)
    Console.WriteLine("GetFileName('{0}') returns '{1}'", pathname, result)

    Call MySub()

End Sub

Sub MySub()
    'Move Files

    For Each f As String In fList
        'Remove path from the file name. 
        Dim fName As String = f.Substring(sourceDir.Length = 0)
        Dim sourceFile = Path.Combine(sourceDir, fName)
        Dim processedFileDir = Path.Combine(processedDir, fName)

        ' Use the Path.Combine method to safely append the file name to the path. 
        ' Will overwrite if the destination file already exists.
        File.Copy(Path.Combine(sourceDir, fName), Path.Combine(processedDir, fName), True)
        'File.Copy(sourceFile, processedFileDir)

    Next f
End Sub

端模块

4

1 回答 1

2

我以前用过这个:

FileWath 类

对于轮询目录以了解结构和文件详细信息等的更改非常有用。

然后,您可以使用来获取文件的扩展名,如果它符合您的条件,则执行一些操作。

这些链接带有示例,请尽情享受!

Sub MySub()
    'Move Files

    For Each f As String In fList

        Dim fInfo As FileInfo = New FileInfo(f)

        Dim fName As String = fInfo.Name

        Dim processedFileDir = Path.Combine(processedDir, fName)

        ' Use the Path.Combine method to safely append the file name to the path. 
        ' Will overwrite if the destination file already exists.
        File.Copy(fInfo.FullName, processedFileDir, True)

    Next f
End Sub
于 2012-11-21T11:38:47.680 回答