本文整理汇总了C++中GetFileAttributesExW函数的典型用法代码示例。如果您正苦于以下问题:C++ GetFileAttributesExW函数的具体用法?C++ GetFileAttributesExW怎么用?C++ GetFileAttributesExW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetFileAttributesExW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hooked_stat
//------------------------------------------------------------------------------
int hooked_stat(const char* path, struct hooked_stat* out)
{
int ret = -1;
WIN32_FILE_ATTRIBUTE_DATA fad;
wchar_t buf[2048];
size_t characters;
// Utf8 to wchars.
characters = MultiByteToWideChar(
CP_UTF8, 0,
path, -1,
buf, sizeof_array(buf)
);
characters = characters ? characters : sizeof_array(buf) - 1;
buf[characters] = L'\0';
// Get properties.
out->st_size = 0;
out->st_mode = 0;
if (GetFileAttributesExW(buf, GetFileExInfoStandard, &fad) != 0)
{
unsigned dir_bit;
dir_bit = (fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR : 0;
out->st_size = fad.nFileSizeLow;
out->st_mode |= dir_bit;
ret = 0;
}
else
errno = ENOENT;
return ret;
}
示例2: omrfile_length
int64_t
omrfile_length(struct OMRPortLibrary *portLibrary, const char *path)
{
int64_t result = -1;
wchar_t unicodeBuffer[UNICODE_BUFFER_SIZE], *unicodePath;
Trc_PRT_file_length_Entry(path);
/* Convert the filename from UTF8 to Unicode */
unicodePath = file_get_unicode_path(portLibrary, path, unicodeBuffer, UNICODE_BUFFER_SIZE);
if (NULL != unicodePath) {
WIN32_FILE_ATTRIBUTE_DATA myStat;
if (0 == GetFileAttributesExW(unicodePath, GetFileExInfoStandard, &myStat)) {
int32_t error = GetLastError();
result = portLibrary->error_set_last_error(portLibrary, error, findError(error));
} else {
result = ((int64_t)myStat.nFileSizeHigh) << 32;
result += (int64_t)myStat.nFileSizeLow;
}
if (unicodeBuffer != unicodePath) {
portLibrary->mem_free_memory(portLibrary, unicodePath);
}
}
Trc_PRT_file_length_Exit(result);
return result;
}
示例3: FileMonikerImpl_GetTimeOfLastChange
/******************************************************************************
* FileMoniker_GetTimeOfLastChange
******************************************************************************/
static HRESULT WINAPI
FileMonikerImpl_GetTimeOfLastChange(IMoniker* iface, IBindCtx* pbc,
IMoniker* pmkToLeft, FILETIME* pFileTime)
{
FileMonikerImpl *This = impl_from_IMoniker(iface);
IRunningObjectTable* rot;
HRESULT res;
WIN32_FILE_ATTRIBUTE_DATA info;
TRACE("(%p,%p,%p,%p)\n",iface,pbc,pmkToLeft,pFileTime);
if (pFileTime==NULL)
return E_POINTER;
if (pmkToLeft!=NULL)
return E_INVALIDARG;
res=IBindCtx_GetRunningObjectTable(pbc,&rot);
if (FAILED(res))
return res;
res= IRunningObjectTable_GetTimeOfLastChange(rot,iface,pFileTime);
if (FAILED(res)){ /* the moniker is not registered */
if (!GetFileAttributesExW(This->filePathName,GetFileExInfoStandard,&info))
return MK_E_NOOBJECT;
*pFileTime=info.ftLastWriteTime;
}
return S_OK;
}
示例4: stat
bool fs::stat(const std::string& path, stat_t& info)
{
g_tls_error = fse::ok;
#ifdef _WIN32
WIN32_FILE_ATTRIBUTE_DATA attrs;
if (!GetFileAttributesExW(to_wchar(path).get(), GetFileExInfoStandard, &attrs))
{
return false;
}
info.is_directory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
info.is_writable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
info.size = (u64)attrs.nFileSizeLow | ((u64)attrs.nFileSizeHigh << 32);
info.atime = to_time_t(attrs.ftLastAccessTime);
info.mtime = to_time_t(attrs.ftLastWriteTime);
info.ctime = to_time_t(attrs.ftCreationTime);
#else
struct stat file_info;
if (stat(path.c_str(), &file_info) < 0)
{
return false;
}
info.is_directory = S_ISDIR(file_info.st_mode);
info.is_writable = file_info.st_mode & 0200; // HACK: approximation
info.size = file_info.st_size;
info.atime = file_info.st_atime;
info.mtime = file_info.st_mtime;
info.ctime = file_info.st_ctime;
#endif
return true;
}
示例5: _wchmod
// Changes the mode of a file. The only supported mode bit is _S_IWRITE, which
// controls the user write (read-only) attribute of the file. Returns zero if
// successful; returns -1 and sets errno and _doserrno on failure.
extern "C" int __cdecl _wchmod(wchar_t const* const path, int const mode)
{
_VALIDATE_CLEAR_OSSERR_RETURN(path != nullptr, EINVAL, -1);
WIN32_FILE_ATTRIBUTE_DATA attributes;
if (!GetFileAttributesExW(path, GetFileExInfoStandard, &attributes))
{
__acrt_errno_map_os_error(GetLastError());
return -1;
}
// Set or clear the read-only flag:
if (mode & _S_IWRITE)
{
attributes.dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY;
}
else
{
attributes.dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
}
if (!SetFileAttributesW(path, attributes.dwFileAttributes))
{
__acrt_errno_map_os_error(GetLastError());
return -1;
}
return 0;
}
示例6: Java_net_rubygrapefruit_platform_internal_jni_WindowsFileFunctions_stat
JNIEXPORT void JNICALL
Java_net_rubygrapefruit_platform_internal_jni_WindowsFileFunctions_stat(JNIEnv *env, jclass target, jstring path, jobject dest, jobject result) {
jclass destClass = env->GetObjectClass(dest);
jmethodID mid = env->GetMethodID(destClass, "details", "(IJJ)V");
if (mid == NULL) {
mark_failed_with_message(env, "could not find method", result);
return;
}
WIN32_FILE_ATTRIBUTE_DATA attr;
wchar_t* pathStr = java_to_wchar(env, path, result);
BOOL ok = GetFileAttributesExW(pathStr, GetFileExInfoStandard, &attr);
free(pathStr);
if (!ok) {
DWORD error = GetLastError();
if (error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND || error == ERROR_NOT_READY) {
// Treat device with no media as missing
env->CallVoidMethod(dest, mid, (jint)FILE_TYPE_MISSING, (jlong)0, (jlong)0);
return;
}
mark_failed_with_errno(env, "could not file attributes", result);
return;
}
jlong lastModified = lastModifiedNanos(&attr.ftLastWriteTime);
if (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
env->CallVoidMethod(dest, mid, (jint)FILE_TYPE_DIRECTORY, (jlong)0, lastModified);
} else {
jlong size = ((jlong)attr.nFileSizeHigh << 32) | attr.nFileSizeLow;
env->CallVoidMethod(dest, mid, (jint)FILE_TYPE_FILE, size, lastModified);
}
}
示例7: win32_wstat
/*
* The CRT of Windows has a number of flaws wrt. its stat() implementation:
* - time stamps are restricted to second resolution
* - file modification times suffer from forth-and-back conversions between
* UTC and local time
* Therefore, we implement our own stat, based on the Win32 API directly.
*
* This is based on the Python 2 implementation from:
* https://github.com/python/cpython/commit/14694662d530d0d1823e1d86f2e5b2e4ec600e86#diff-a6f29e907cbb5fffd44d453bcd7b77d5R741
*/
static int
win32_wstat(const wchar_t* path, struct meterp_stat *result)
{
int code;
const wchar_t *dot;
WIN32_FILE_ATTRIBUTE_DATA info;
if (!GetFileAttributesExW(path, GetFileExInfoStandard, &info)) {
if (GetLastError() != ERROR_SHARING_VIOLATION) {
return -1;
}
else {
if (!attributes_from_dir_w(path, &info)) {
return -1;
}
}
}
code = attribute_data_to_stat(&info, result);
if (code < 0) {
return code;
}
/* Set IFEXEC if it is an .exe, .bat, ... */
dot = wcsrchr(path, '.');
if (dot) {
if (_wcsicmp(dot, L".bat") == 0 ||
_wcsicmp(dot, L".cmd") == 0 ||
_wcsicmp(dot, L".exe") == 0 ||
_wcsicmp(dot, L".com") == 0)
result->st_mode |= 0111;
}
return code;
}
示例8: omrfile_lastmod
int64_t
omrfile_lastmod(struct OMRPortLibrary *portLibrary, const char *path)
{
int64_t result = -1;
wchar_t unicodeBuffer[UNICODE_BUFFER_SIZE], *unicodePath;
Trc_PRT_file_lastmod_Entry(path);
/* Convert the filename from UTF8 to Unicode */
unicodePath = file_get_unicode_path(portLibrary, path, unicodeBuffer, UNICODE_BUFFER_SIZE);
if (NULL != unicodePath) {
WIN32_FILE_ATTRIBUTE_DATA myStat;
if (0 == GetFileAttributesExW(unicodePath, GetFileExInfoStandard, &myStat)) {
int32_t error = GetLastError();
result = portLibrary->error_set_last_error(portLibrary, error, findError(error));
} else {
/*
* Search MSDN for 'Converting a time_t Value to a File Time' for following implementation.
*/
result = ((int64_t) myStat.ftLastWriteTime.dwHighDateTime << 32) | (int64_t) myStat.ftLastWriteTime.dwLowDateTime;
result = (result - 116444736000000000) / 10000;
}
if (unicodeBuffer != unicodePath) {
portLibrary->mem_free_memory(portLibrary, unicodePath);
}
}
Trc_PRT_file_lastmod_Exit(result);
return result;
}
示例9: _EbrIsDir
static bool _EbrIsDir(const wchar_t* path) {
WIN32_FILE_ATTRIBUTE_DATA fileAttribData;
if (GetFileAttributesExW(path, GetFileExInfoStandard, &fileAttribData)) {
if ((fileAttribData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
return true;
}
return false;
}
示例10: tr_sys_path_get_info
bool tr_sys_path_get_info(char const* path, int flags, tr_sys_path_info* info, tr_error** error)
{
TR_ASSERT(path != NULL);
TR_ASSERT(info != NULL);
bool ret = false;
wchar_t* wide_path = path_to_native_path(path);
if ((flags & TR_SYS_PATH_NO_FOLLOW) == 0)
{
HANDLE handle = INVALID_HANDLE_VALUE;
if (wide_path != NULL)
{
handle = CreateFileW(wide_path, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
}
if (handle != INVALID_HANDLE_VALUE)
{
tr_error* my_error = NULL;
ret = tr_sys_file_get_info(handle, info, &my_error);
if (!ret)
{
tr_error_propagate(error, &my_error);
}
CloseHandle(handle);
}
else
{
set_system_error(error, GetLastError());
}
}
else
{
WIN32_FILE_ATTRIBUTE_DATA attributes;
if (wide_path != NULL)
{
ret = GetFileAttributesExW(wide_path, GetFileExInfoStandard, &attributes);
}
if (ret)
{
stat_to_sys_path_info(attributes.dwFileAttributes, attributes.nFileSizeLow, attributes.nFileSizeHigh,
&attributes.ftLastWriteTime, info);
}
else
{
set_system_error(error, GetLastError());
}
}
tr_free(wide_path);
return ret;
}
示例11: doPlatformExists
static int doPlatformExists(LPWSTR wpath)
{
WIN32_FILE_ATTRIBUTE_DATA a;
// Returns non-zero if successful
BOOL retval = GetFileAttributesExW(wpath, GetFileExInfoStandard, &a);
return(retval);
} /* doPlatformExists */
示例12: CHECK_WIN32_BOOL
long DVLib::GetFileSize(const std::wstring& filename)
{
WIN32_FILE_ATTRIBUTE_DATA attr = { 0 };
CHECK_WIN32_BOOL(GetFileAttributesExW(filename.c_str(), GetFileExInfoStandard, & attr),
L"Error getting file attributes of " << filename);
CHECK_BOOL(0 == attr.nFileSizeHigh,
L"File " << filename << L" is > 2GB (" << attr.nFileSizeHigh << ")");
return (long) attr.nFileSizeLow;
}
示例13: GetFileAttributesW
DWORD WINAPI_DECL GetFileAttributesW(
_In_ LPCWSTR lpFileName
)
{
WIN32_FILE_ATTRIBUTE_DATA fileInformation;
BOOL b = GetFileAttributesExW(
lpFileName,
GetFileExInfoStandard,
&fileInformation);
return b ? fileInformation.dwFileAttributes : INVALID_FILE_ATTRIBUTES;
}
示例14: GetFileAttributesExW
void WinNode::stat_impl(NodeStat& dst)
{
WIN32_FILE_ATTRIBUTE_DATA attrs = { 0 };
GetFileAttributesExW(m_nativePath.c_str(), GetFileExInfoStandard, &attrs);
filetimeToUint64(dst.ctime, attrs.ftCreationTime);
filetimeToUint64(dst.mtime, attrs.ftLastWriteTime);
filetimeToUint64(dst.atime, attrs.ftLastAccessTime);
dst.id = m_id;
dst.size = ((uint64)attrs.nFileSizeHigh << 32) | attrs.nFileSizeLow;
}
示例15: memset
ticks_t Platform::getFileModificationTime(std::string file)
{
boost::replace_all(file, "/", "\\");
std::wstring wfile = stdext::utf8_to_utf16(file);
WIN32_FILE_ATTRIBUTE_DATA fileAttrData;
memset(&fileAttrData, 0, sizeof(fileAttrData));
GetFileAttributesExW(wfile.c_str(), GetFileExInfoStandard, &fileAttrData);
ULARGE_INTEGER uli;
uli.LowPart = fileAttrData.ftLastWriteTime.dwLowDateTime;
uli.HighPart = fileAttrData.ftLastWriteTime.dwHighDateTime;
return uli.QuadPart;
}