2012-11-21 3 views
2

활성 디렉토리를 폴링하는 콘솔 응용 프로그램을 생성하라는 메시지가 표시되었습니다. (C. \ Temp \ Input)VB.net Dir의 파일 이름 읽기 SQL 쿼리 실행

파일이 (filename).SUCCESS과 함께 들어 오면 SQL 쿼리를 실행하기 위해 파일 이름이 검색됩니다. 따라서

IF fileextension = SUCCESS 

SQL 테이블에서 파일 이름을 사용하여 SQL 쿼리를 실행하여 SQL 쿼리를 실행합니다. 원래 파일을 c:\temp\Input\Processed

으로 옮깁니다. 도움이나 조언을 주시면 감사하겠습니다.

업데이트 :

안녕하세요, 여러 사이트 IV에서 몇 가지 모양으로 아래 마련. 지금은 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 

내가 전에 사용했습니다

답변

2

엔드 모듈 :

The FileWather Class

구조 및 파일 세부 사항의 변경 사항에 대한 디렉토리 폴링에 유용합니다. this을 사용하여 파일의 확장자를 가져오고 조건에 맞는 경우 일부 작업을 수행 할 수 있습니다.

이러한 링크는 예제와 함께 제공됩니다!

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 
+0

많은 분들께 감사드립니다. – Gerry85

+0

우수. 데이터 조작에 대한 당신의 접근 방식은 당신이 당신의 RDBMS (mysql, sql-server etc)를 어떻게하고 싶은지에 달려 있으며, 파일 이동의 처리는 매우 간단하고 머리 위로 떨어져있다. System.IO.File.Move (sourceFilePath, destinationFilePath) – Ric

+0

환호성 Ric, SQL Server에 연결하여 jobId의 상태를 변경하려고합니다. ID는 확장명 앞에있는 파일 이름입니다. – Gerry85