2
我被要求創建一個輪詢活動目錄的控制檯應用程序。 (C. \ Temp \ Input)VB.net從Dir讀取文件名以運行SQL查詢
當文件進入(filename).SUCCESS
時,將檢索文件名以運行SQL查詢。因此,
IF fileextension = SUCCESS
使用文件名運行SQL查詢以更改SQL表中的值。 移動原始文件到c:\temp\Input\Processed
任何幫助或提示將不勝感激。
更新:
嗨,與不同IV的景點僅有長相拿出下方。忘了SQL現在,我只是後的文件名和文件,但即時得到IO異常的移動該文件已在使用:
進口System.IO 進口System.String 模塊模塊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
前端模塊
很多謝謝生病給了這個鏡頭。 – Gerry85
優秀。你的數據操作方法取決於你想要做什麼以及你的RDBMS(mysql,sql-server等)和文件移動的處理是非常簡單的,並且離開我的頭頂它的System.IO.File.Move sourceFilePath,destinationFilePath) – Ric
Cheers Ric,我想連接到SQL Server並運行更改jobId的狀態,ID是擴展名之前的文件名。 – Gerry85