Win32 API 日本語リファレンス
ホームStorage.FileSystem › GetFileAttributesExA

GetFileAttributesExA

関数
指定ファイルの属性や時刻などの拡張情報を取得する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

BOOL GetFileAttributesExA(
    LPCSTR lpFileName,
    GET_FILEEX_INFO_LEVELS fInfoLevelId,
    void* lpFileInformation
);

パラメーター

名前方向
lpFileNameLPCSTRin
fInfoLevelIdGET_FILEEX_INFO_LEVELSin
lpFileInformationvoid*out

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

BOOL GetFileAttributesExA(
    LPCSTR lpFileName,
    GET_FILEEX_INFO_LEVELS fInfoLevelId,
    void* lpFileInformation
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool GetFileAttributesExA(
    [MarshalAs(UnmanagedType.LPStr)] string lpFileName,   // LPCSTR
    int fInfoLevelId,   // GET_FILEEX_INFO_LEVELS
    IntPtr lpFileInformation   // void* out
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetFileAttributesExA(
    <MarshalAs(UnmanagedType.LPStr)> lpFileName As String,   ' LPCSTR
    fInfoLevelId As Integer,   ' GET_FILEEX_INFO_LEVELS
    lpFileInformation As IntPtr   ' void* out
) As Boolean
End Function
' lpFileName : LPCSTR
' fInfoLevelId : GET_FILEEX_INFO_LEVELS
' lpFileInformation : void* out
Declare PtrSafe Function GetFileAttributesExA Lib "kernel32" ( _
    ByVal lpFileName As String, _
    ByVal fInfoLevelId As Long, _
    ByVal lpFileInformation As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetFileAttributesExA = ctypes.windll.kernel32.GetFileAttributesExA
GetFileAttributesExA.restype = wintypes.BOOL
GetFileAttributesExA.argtypes = [
    wintypes.LPCSTR,  # lpFileName : LPCSTR
    ctypes.c_int,  # fInfoLevelId : GET_FILEEX_INFO_LEVELS
    ctypes.POINTER(None),  # lpFileInformation : void* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetFileAttributesExA = Fiddle::Function.new(
  lib['GetFileAttributesExA'],
  [
    Fiddle::TYPE_VOIDP,  # lpFileName : LPCSTR
    Fiddle::TYPE_INT,  # fInfoLevelId : GET_FILEEX_INFO_LEVELS
    Fiddle::TYPE_VOIDP,  # lpFileInformation : void* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetFileAttributesExA(
        lpFileName: *const u8,  // LPCSTR
        fInfoLevelId: i32,  // GET_FILEEX_INFO_LEVELS
        lpFileInformation: *mut ()  // void* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool GetFileAttributesExA([MarshalAs(UnmanagedType.LPStr)] string lpFileName, int fInfoLevelId, IntPtr lpFileInformation);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetFileAttributesExA' -Namespace Win32 -PassThru
# $api::GetFileAttributesExA(lpFileName, fInfoLevelId, lpFileInformation)
#uselib "KERNEL32.dll"
#func global GetFileAttributesExA "GetFileAttributesExA" sptr, sptr, sptr
; GetFileAttributesExA lpFileName, fInfoLevelId, lpFileInformation   ; 戻り値は stat
; lpFileName : LPCSTR -> "sptr"
; fInfoLevelId : GET_FILEEX_INFO_LEVELS -> "sptr"
; lpFileInformation : void* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global GetFileAttributesExA "GetFileAttributesExA" str, int, sptr
; res = GetFileAttributesExA(lpFileName, fInfoLevelId, lpFileInformation)
; lpFileName : LPCSTR -> "str"
; fInfoLevelId : GET_FILEEX_INFO_LEVELS -> "int"
; lpFileInformation : void* out -> "sptr"
; BOOL GetFileAttributesExA(LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, void* lpFileInformation)
#uselib "KERNEL32.dll"
#cfunc global GetFileAttributesExA "GetFileAttributesExA" str, int, intptr
; res = GetFileAttributesExA(lpFileName, fInfoLevelId, lpFileInformation)
; lpFileName : LPCSTR -> "str"
; fInfoLevelId : GET_FILEEX_INFO_LEVELS -> "int"
; lpFileInformation : void* out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetFileAttributesExA = kernel32.NewProc("GetFileAttributesExA")
)

// lpFileName (LPCSTR), fInfoLevelId (GET_FILEEX_INFO_LEVELS), lpFileInformation (void* out)
r1, _, err := procGetFileAttributesExA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpFileName))),
	uintptr(fInfoLevelId),
	uintptr(lpFileInformation),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetFileAttributesExA(
  lpFileName: PAnsiChar;   // LPCSTR
  fInfoLevelId: Integer;   // GET_FILEEX_INFO_LEVELS
  lpFileInformation: Pointer   // void* out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'GetFileAttributesExA';
result := DllCall("KERNEL32\GetFileAttributesExA"
    , "AStr", lpFileName   ; LPCSTR
    , "Int", fInfoLevelId   ; GET_FILEEX_INFO_LEVELS
    , "Ptr", lpFileInformation   ; void* out
    , "Int")   ; return: BOOL
●GetFileAttributesExA(lpFileName, fInfoLevelId, lpFileInformation) = DLL("KERNEL32.dll", "bool GetFileAttributesExA(char*, int, void*)")
# 呼び出し: GetFileAttributesExA(lpFileName, fInfoLevelId, lpFileInformation)
# lpFileName : LPCSTR -> "char*"
# fInfoLevelId : GET_FILEEX_INFO_LEVELS -> "int"
# lpFileInformation : void* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。