VB.net从目录读取文件名以运行SQL查询

VB.net从目录读取文件名以运行SQL查询,sql,vb.net,Sql,Vb.net,我被要求创建一个轮询active Directory的控制台应用程序。(C.\Temp\Input) 当文件带有(filename).SUCCESS时,将检索文件名以运行SQL查询。所以 IF fileextension = SUCCESS 使用文件名运行SQL查询以更改SQL表中的值。 将原始文件移动到c:\temp\Input\Processed 任何帮助或暗示都将不胜感激 更新: 大家好,通过对不同网站的一些了解,我得出以下结论。暂时忘记SQL,我只是在文件名和文件移动之后才开始,但我收

我被要求创建一个轮询active Directory的控制台应用程序。(C.\Temp\Input)

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

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

任何帮助或暗示都将不胜感激

更新:

大家好,通过对不同网站的一些了解,我得出以下结论。暂时忘记SQL,我只是在文件名和文件移动之后才开始,但我收到一个IO异常,文件已经在使用中:

导入System.IO 导入系统字符串 模块1

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
结束模块

我以前用过这个:

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

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

这些链接带有示例,请欣赏

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

非常感谢,我来试一试。太好了。你处理数据的方法取决于你想做什么和你的RDBMS(mysql、sql server等),文件移动的处理非常简单,我不知道它的System.IO.file.Move(sourceFilePath、destinationFilePath)干杯Ric,我想连接到sql server并运行更改jobId状态,ID是扩展名之前的文件名。很好,这就解决了。干杯。如果您能将其标记为答案,我们将不胜感激!