Win32 API 日本語リファレンス
ホームUI.Shell › PathFileExistsA

PathFileExistsA

関数
指定したパスのファイルまたはフォルダが存在するか判定する。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL PathFileExistsA(
    LPCSTR pszPath
);

パラメーター

名前方向
pszPathLPCSTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

PathFileExistsA = ctypes.windll.shlwapi.PathFileExistsA
PathFileExistsA.restype = wintypes.BOOL
PathFileExistsA.argtypes = [
    wintypes.LPCSTR,  # pszPath : LPCSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathFileExistsA = shlwapi.NewProc("PathFileExistsA")
)

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