我被要求创建一个轮询活动目录的控制台应用程序。(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
端模块