2012-02-10 3 views
2

DB 내의 데이터를 기반으로 한 위치에서 다른 위치로 파일을 이동하는 양식을 만들고 원본 파일이 암호화되지 않은 한 작동합니다 (녹색 Windows 탐색기의 파일 이름) 및 대상 파일이 존재하지 않는 한.VBA (MSAccess)에서 파일 암호화를 확인하는 방법

Public Function isEncrypted(file As String) As Boolean 
    Dim info As System.IO.FileInfo 
    info = My.Computer.FileSystem.GetFileInfo(file) 

    Dim attr As System.IO.FileAttributes 
    attr = info.Attributes 

    isEncrypted = ((attr And System.IO.FileAttributes.Encrypted) > 0) 
End Function 

을하지만 전혀 실행되지 않습니다

그래서 나는 다음과 같은 만들려고 해요. 누구나이 경험이 있거나 암호화를 확인하는 더 쉬운 방법이 있습니까? &의 이름을 바꿔 암호화 된 파일로 옮기면 액세스가 중단되고 중단됩니다.

+0

어떻게 VBA 코드에서'System.IO.FileAttributes'를 사용할 수 있습니까? Dim 문은 시스템에서 컴파일러 오류를 발생시킵니다. – HansUp

+2

@ HansUp의 의견에 따라야합니다. 작성한 코드는 VB.NET 코드입니다. VBA는 완전히 다른 동물 인 VB 6을 기반으로합니다. – phoog

답변

3

다른 언급했듯이 vb.net 코드가 액세스 할 때 컴파일 될 방법이 없습니다. 파일 속성을 얻으려면 win32에서 시스템 호출을 사용해야 할 가능성이 큽니다. FileSystemObject (Scrrun.dll 'Windows Scripting Runtime') 개체는 열거 형에서 파일이 암호화되었는지 알려주지 않으므로 작동하지 않습니다. 다음은 파일 암호화 여부를 결정하는 데 사용할 수있는 Windows API 함수입니다.

Public Enum FileAttribute 
'uses VBA Hex Notation 
    FILE_ATTRIBUTE_READONLY = &H1 
    FILE_ATTRIBUTE_HIDDEN = &H2 
    FILE_ATTRIBUTE_SYSTEM = &H4 
    FILE_ATTRIBUTE_DIRECTORY = &H10 
    FILE_ATTRIBUTE_ARCHIVE = &H20 
    FILE_ATTRIBUTE_DEVICE = &H40 
    FILE_ATTRIBUTE_NORMAL = &H80 
    FILE_ATTRIBUTE_TEMPORARY = &H100 
    FILE_ATTRIBUTE_SPARSE_FILE = &H200 
    FILE_ATTRIBUTE_REPARSE_POINT = &H400 
    FILE_ATTRIBUTE_COMPRESSED = &H800 
    FILE_ATTRIBUTE_OFFLINE = &H1000 
    FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = &H2000 
    FILE_ATTRIBUTE_ENCRYPTED = &H4000 
    FILE_ATTRIBUTE_VIRTUAL = &H10000 
End Enum 

Private Declare Function GetFileAttributes Lib "kernel32.dll" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long 

Public Sub Test() 

    Dim fileTestPath As String 
    Dim attributes As Long 

    fileTestPath = "C:\yourfile.txt" 

    attributes = GetFileAttributes(fileTestPath) 

    'uses bitwise AND calculations to determine values 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_ARCHIVE) Then Debug.Print "Archive" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_COMPRESSED) Then Debug.Print "Compressed" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_DEVICE) Then Debug.Print "Device" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_DIRECTORY) Then Debug.Print "Directory" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_ENCRYPTED) Then Debug.Print "Encrypted" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_HIDDEN) Then Debug.Print "Hidden" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_NORMAL) Then Debug.Print "Normal" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) Then Debug.Print "Not Content Indexed" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_OFFLINE) Then Debug.Print "Offline" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_READONLY) Then Debug.Print "ReadOnly" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_REPARSE_POINT) Then Debug.Print "ReparsePoint" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_SPARSE_FILE) Then Debug.Print "SparseFile" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_SYSTEM) Then Debug.Print "System" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_TEMPORARY) Then Debug.Print "Temporary" 
    If (attributes And FileAttribute.FILE_ATTRIBUTE_VIRTUAL) Then Debug.Print "Virtual" 

End Sub 
+0

매력처럼 작동했습니다! 도와 주셔서 감사합니다 :) –

관련 문제