ホーム › Storage.FileSystem › GetFileAttributesExW
GetFileAttributesExW
関数指定ファイルの属性や時刻などの拡張情報を取得する。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL GetFileAttributesExW(
LPCWSTR lpFileName,
GET_FILEEX_INFO_LEVELS fInfoLevelId,
void* lpFileInformation
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpFileName | LPCWSTR | in |
| fInfoLevelId | GET_FILEEX_INFO_LEVELS | in |
| lpFileInformation | void* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL GetFileAttributesExW(
LPCWSTR lpFileName,
GET_FILEEX_INFO_LEVELS fInfoLevelId,
void* lpFileInformation
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool GetFileAttributesExW(
[MarshalAs(UnmanagedType.LPWStr)] string lpFileName, // LPCWSTR
int fInfoLevelId, // GET_FILEEX_INFO_LEVELS
IntPtr lpFileInformation // void* out
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetFileAttributesExW(
<MarshalAs(UnmanagedType.LPWStr)> lpFileName As String, ' LPCWSTR
fInfoLevelId As Integer, ' GET_FILEEX_INFO_LEVELS
lpFileInformation As IntPtr ' void* out
) As Boolean
End Function' lpFileName : LPCWSTR
' fInfoLevelId : GET_FILEEX_INFO_LEVELS
' lpFileInformation : void* out
Declare PtrSafe Function GetFileAttributesExW Lib "kernel32" ( _
ByVal lpFileName As LongPtr, _
ByVal fInfoLevelId As Long, _
ByVal lpFileInformation As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetFileAttributesExW = ctypes.windll.kernel32.GetFileAttributesExW
GetFileAttributesExW.restype = wintypes.BOOL
GetFileAttributesExW.argtypes = [
wintypes.LPCWSTR, # lpFileName : LPCWSTR
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')
GetFileAttributesExW = Fiddle::Function.new(
lib['GetFileAttributesExW'],
[
Fiddle::TYPE_VOIDP, # lpFileName : LPCWSTR
Fiddle::TYPE_INT, # fInfoLevelId : GET_FILEEX_INFO_LEVELS
Fiddle::TYPE_VOIDP, # lpFileInformation : void* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn GetFileAttributesExW(
lpFileName: *const u16, // LPCWSTR
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.Unicode, SetLastError = true)]
public static extern bool GetFileAttributesExW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, int fInfoLevelId, IntPtr lpFileInformation);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetFileAttributesExW' -Namespace Win32 -PassThru
# $api::GetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation)#uselib "KERNEL32.dll"
#func global GetFileAttributesExW "GetFileAttributesExW" wptr, wptr, wptr
; GetFileAttributesExW lpFileName, fInfoLevelId, lpFileInformation ; 戻り値は stat
; lpFileName : LPCWSTR -> "wptr"
; fInfoLevelId : GET_FILEEX_INFO_LEVELS -> "wptr"
; lpFileInformation : void* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global GetFileAttributesExW "GetFileAttributesExW" wstr, int, sptr
; res = GetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation)
; lpFileName : LPCWSTR -> "wstr"
; fInfoLevelId : GET_FILEEX_INFO_LEVELS -> "int"
; lpFileInformation : void* out -> "sptr"; BOOL GetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, void* lpFileInformation)
#uselib "KERNEL32.dll"
#cfunc global GetFileAttributesExW "GetFileAttributesExW" wstr, int, intptr
; res = GetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation)
; lpFileName : LPCWSTR -> "wstr"
; fInfoLevelId : GET_FILEEX_INFO_LEVELS -> "int"
; lpFileInformation : void* out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetFileAttributesExW = kernel32.NewProc("GetFileAttributesExW")
)
// lpFileName (LPCWSTR), fInfoLevelId (GET_FILEEX_INFO_LEVELS), lpFileInformation (void* out)
r1, _, err := procGetFileAttributesExW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
uintptr(fInfoLevelId),
uintptr(lpFileInformation),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetFileAttributesExW(
lpFileName: PWideChar; // LPCWSTR
fInfoLevelId: Integer; // GET_FILEEX_INFO_LEVELS
lpFileInformation: Pointer // void* out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetFileAttributesExW';result := DllCall("KERNEL32\GetFileAttributesExW"
, "WStr", lpFileName ; LPCWSTR
, "Int", fInfoLevelId ; GET_FILEEX_INFO_LEVELS
, "Ptr", lpFileInformation ; void* out
, "Int") ; return: BOOL●GetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation) = DLL("KERNEL32.dll", "bool GetFileAttributesExW(char*, int, void*)")
# 呼び出し: GetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation)
# lpFileName : LPCWSTR -> "char*"
# fInfoLevelId : GET_FILEEX_INFO_LEVELS -> "int"
# lpFileInformation : void* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。