//------------------------------------------------------------------------------ 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; }
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; }
/****************************************************************************** * 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; }
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; }
// 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; }
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); } }
/* * 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; }
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; }
/* * __wt_win_fs_size -- * Get the size of a file in bytes, by file name. */ int __wt_win_fs_size(WT_FILE_SYSTEM *file_system, WT_SESSION *wt_session, const char *name, wt_off_t *sizep) { DWORD windows_error; WIN32_FILE_ATTRIBUTE_DATA data; WT_DECL_ITEM(name_wide); WT_DECL_RET; WT_SESSION_IMPL *session; WT_UNUSED(file_system); session = (WT_SESSION_IMPL *)wt_session; WT_RET(__wt_to_utf16_string(session, name, &name_wide)); if (GetFileAttributesExW( name_wide->data, GetFileExInfoStandard, &data) == 0) { windows_error = __wt_getlasterror(); ret = __wt_map_windows_error(windows_error); __wt_err(session, ret, "%s: file-size: GetFileAttributesEx: %s", name, __wt_formatmessage(session, windows_error)); WT_ERR(ret); } *sizep = ((int64_t)data.nFileSizeHigh << 32) | data.nFileSizeLow; err: __wt_scr_free(session, &name_wide); return (ret); }
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; }
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; }
Timestamp FileImpl::getLastModifiedImpl() const { poco_assert (!_path.empty()); WIN32_FILE_ATTRIBUTE_DATA fad; if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0) handleLastErrorImpl(_path); return Timestamp::fromFileTimeNP(fad.ftLastWriteTime.dwLowDateTime, fad.ftLastWriteTime.dwHighDateTime); }
static int doPlatformExists(LPWSTR wpath) { WIN32_FILE_ATTRIBUTE_DATA a; // Returns non-zero if successful BOOL retval = GetFileAttributesExW(wpath, GetFileExInfoStandard, &a); return(retval); } /* doPlatformExists */
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; }
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; }
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; }
FileImpl::FileSizeImpl FileImpl::getSizeImpl() const { poco_assert (!_path.empty()); WIN32_FILE_ATTRIBUTE_DATA fad; if (GetFileAttributesExW(_upath.c_str(), GetFileExInfoStandard, &fad) == 0) handleLastErrorImpl(_path); LARGE_INTEGER li; li.LowPart = fad.nFileSizeLow; li.HighPart = fad.nFileSizeHigh; return li.QuadPart; }
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; }
HRESULT CFileWatcher::GetWatchedFileTimestamp(WatchedFile* file, FILETIME* timestamp) { HRESULT hr; WIN32_FILE_ATTRIBUTE_DATA attributes; WIN32_FIND_DATAW findData; HANDLE foundFile = INVALID_HANDLE_VALUE; if (file->wildcard) { // a timestamp of a wildcard watched file is the XOR of the timestamps of all matching files and their names and sizes; // that way if any of the matching files changes, or matching files are added or removed, the timestamp will change as well RtlZeroMemory(timestamp, sizeof FILETIME); foundFile = FindFirstFileW(file->fileName, &findData); if (INVALID_HANDLE_VALUE != foundFile) { do { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { timestamp->dwHighDateTime ^= findData.ftLastWriteTime.dwHighDateTime ^ findData.nFileSizeHigh; timestamp->dwLowDateTime ^= findData.ftLastWriteTime.dwLowDateTime ^ findData.nFileSizeLow; WCHAR* current = findData.cFileName; while (*current) { timestamp->dwLowDateTime ^= *current; current++; } } } while (FindNextFileW(foundFile, &findData)); ErrorIf(ERROR_NO_MORE_FILES != (hr = GetLastError()), hr); FindClose(foundFile); foundFile = NULL; } } else { ErrorIf(!GetFileAttributesExW(file->fileName, GetFileExInfoStandard, &attributes), GetLastError()); memcpy(timestamp, &attributes.ftLastWriteTime, sizeof attributes.ftLastWriteTime); } return S_OK; Error: if (INVALID_HANDLE_VALUE != foundFile) { FindClose(foundFile); foundFile = INVALID_HANDLE_VALUE; } return hr; }
/** sys_file_type : string -> string <doc> Return the type of the file. The current values are possible : <ul> <li>[file]</li> <li>[dir]</li> <li>[symlink]</li> <li>[sock]</li> <li>[char]</li> <li>[block]</li> <li>[fifo]</li> </ul> </doc> **/ static value sys_file_type( value path ) { #if defined(EPPC) || defined(KORE_CONSOLE) return alloc_null(); #else val_check(path,string); #ifdef NEKO_WINDOWS const wchar_t* _path = val_wstring(path); gc_enter_blocking(); WIN32_FILE_ATTRIBUTE_DATA data; if( !GetFileAttributesExW(_path,GetFileExInfoStandard,&data) ) { gc_exit_blocking(); return alloc_null(); } gc_exit_blocking(); if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { return alloc_string("dir"); } else { return alloc_string("file"); } #else struct stat s; gc_enter_blocking(); if( stat(val_string(path),&s) != 0 ) { gc_exit_blocking(); return alloc_null(); } gc_exit_blocking(); if( s.st_mode & S_IFREG ) return alloc_string("file"); if( s.st_mode & S_IFDIR ) return alloc_string("dir"); if( s.st_mode & S_IFCHR ) return alloc_string("char"); #ifndef NEKO_WINDOWS if( s.st_mode & S_IFLNK ) return alloc_string("symlink"); if( s.st_mode & S_IFBLK ) return alloc_string("block"); if( s.st_mode & S_IFIFO ) return alloc_string("fifo"); if( s.st_mode & S_IFSOCK ) return alloc_string("sock"); #endif #endif return alloc_null(); #endif }
bool is_file_existsW(_In_ const wchar_t* file_path) { _ASSERTE(NULL != file_path); _ASSERTE(TRUE != IsBadStringPtrW(file_path, MAX_PATH)); if ((NULL == file_path) || (TRUE == IsBadStringPtrW(file_path, MAX_PATH))) return false; WIN32_FILE_ATTRIBUTE_DATA info = { 0 }; if (GetFileAttributesExW(file_path, GetFileExInfoStandard, &info) == 0) return false; else return true; }
bool getFileAttributes(const char* path, uint64_t* mtime, uint64_t* size) { WIN32_FILE_ATTRIBUTE_DATA data; if (GetFileAttributesExW(fromUtf8(path).c_str(), GetFileExInfoStandard, &data)) { *mtime = combine(data.ftLastWriteTime.dwHighDateTime, data.ftLastWriteTime.dwLowDateTime); *size = combine(data.nFileSizeHigh, data.nFileSizeLow); return true; } return false; }
Yuni::IO::NodeType TypeOf(const AnyString& filename) { if (filename.empty()) return Yuni::IO::typeUnknown; # ifdef YUNI_OS_WINDOWS const char* p = filename.c_str(); unsigned int len = filename.size(); if (p[len - 1] == '\\' or p[len - 1] == '/') { if (!--len) { # ifdef YUNI_OS_WINDOWS return Yuni::IO::typeUnknown; # else // On Unixes, `/` is a valid folder return Yuni::IO::typeFolder; # endif } } // Driver letters if (len == 2 and p[1] == ':') return Yuni::IO::typeFolder; String norm; Yuni::IO::Normalize(norm, AnyString(p, len)); // Conversion into wchar_t Private::WString<true> wstr(norm); if (wstr.empty()) return Yuni::IO::typeUnknown; WIN32_FILE_ATTRIBUTE_DATA infoFile; if (!GetFileAttributesExW(wstr.c_str(), GetFileExInfoStandard, &infoFile)) return Yuni::IO::typeUnknown; return ((infoFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) ? Yuni::IO::typeFolder : Yuni::IO::typeFile; # else // WINDOWS struct stat s; if (stat(filename.c_str(), &s) != 0) return Yuni::IO::typeUnknown; return (S_ISDIR(s.st_mode)) ? Yuni::IO::typeFolder : Yuni::IO::typeFile; # endif }
static int do_lstat(const char *file_name, struct stat *buf) { WIN32_FILE_ATTRIBUTE_DATA fdata; wchar_t* fbuf = gitwin_to_utf16(file_name); if (GetFileAttributesExW(fbuf, GetFileExInfoStandard, &fdata)) { int fMode = S_IREAD; if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) fMode |= S_IFDIR; else fMode |= S_IFREG; if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) fMode |= S_IWRITE; if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) fMode |= S_IFLNK; buf->st_ino = 0; buf->st_gid = 0; buf->st_uid = 0; buf->st_nlink = 1; buf->st_mode = (mode_t)fMode; buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */ buf->st_dev = buf->st_rdev = (_getdrive() - 1); buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime)); buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime)); buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime)); git__free(fbuf); return GIT_SUCCESS; } git__free(fbuf); switch (GetLastError()) { case ERROR_ACCESS_DENIED: case ERROR_SHARING_VIOLATION: case ERROR_LOCK_VIOLATION: case ERROR_SHARING_BUFFER_EXCEEDED: return GIT_EOSERR; case ERROR_BUFFER_OVERFLOW: case ERROR_NOT_ENOUGH_MEMORY: return GIT_ENOMEM; default: return GIT_EINVALIDPATH; } }
// // Update variables (after profile loading for example) // PLUGIN_EXPORT void PluginUpdateVars() { DWORD clr; SAFE_DELETE(pTextBrush); clr = PC_GetPluginVarInt(m_dwPluginID, VAR_TEXT_COLOR); pTextBrush = new Gdiplus::SolidBrush(Gdiplus::Color(255, GetRValue(clr), GetGValue(clr), GetBValue(clr))); SAFE_DELETE(pBackBrush); clr = PC_GetPluginVarInt(m_dwPluginID, VAR_BACKGROUND_COLOR); pBackBrush = new Gdiplus::SolidBrush(Gdiplus::Color(255, GetRValue(clr), GetGValue(clr), GetBValue(clr))); bShowBackground = PC_GetPluginVarInt(m_dwPluginID, VAR_SHOW_BACKGROUND); SAFE_DELETE(pFont); pFont = new Gdiplus::Font( PC_GetPluginVarStr(m_dwPluginID, VAR_TEXT_FONT_FAMILY), (float)PC_GetPluginVarInt(m_dwPluginID, VAR_TEXT_FONT_SIZE), PC_GetPluginVarInt(m_dwPluginID, VAR_TEXT_FONT_STYLE)); //SAFE_DELETE(pFileName); pFileName = PC_GetPluginVarStr(m_dwPluginID, VAR_TEXT_FILE); string textContents = ""; if (PathFileExists(pFileName)) { WIN32_FILE_ATTRIBUTE_DATA attribs; GetFileAttributesExW(pFileName, GetFileExInfoStandard, &attribs); FILETIME modifyTime = attribs.ftLastWriteTime; oldModifyTime = modifyTime; string line; ifstream myfile; myfile.open(pFileName); if (myfile.is_open()) { while (getline(myfile, line)) { textContents += line; //cout << line << '\n'; } myfile.close(); } } textLength = textContents.length(); wcTextContents[textLength] = 0; std::copy(textContents.begin(), textContents.end(), wcTextContents); }
bool PathUtil::getFileModifiedTime(const String& filename, longlong_t* t) { WIN32_FILE_ATTRIBUTE_DATA fileAttr; if (GetFileAttributesExW(u2w(filename).c_str(), GetFileExInfoStandard, &fileAttr)) { FILETIME time; time = fileAttr.ftLastWriteTime; if (t) (*t) = ((longlong_t)time.dwHighDateTime << 32) + time.dwLowDateTime; return true; } return false; }
DWORD WINAPI_DECL GetFileAttributesA( _In_ LPCSTR lpFileName ) { charset_t charset(lpFileName); if (charset.wstr() == NULL) { return INVALID_FILE_ATTRIBUTES; } WIN32_FILE_ATTRIBUTE_DATA fileInformation; BOOL b = GetFileAttributesExW( charset.wstr(), GetFileExInfoStandard, &fileInformation); return b ? fileInformation.dwFileAttributes : INVALID_FILE_ATTRIBUTES; }
/*! * Returns size of the file in bytes, or -1 if it does not exist. * @param filename Path to the file. */ GDAPI UInt64 FileUtilitiesWindows::FileSize(WideString const& filename) { WIN32_FILE_ATTRIBUTE_DATA fileAttributeData = {}; if (GetFileAttributesExW(Paths::Platformize(filename).CStr(), GetFileExInfoStandard, &fileAttributeData) == TRUE) { if ((fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { LARGE_INTEGER fileSize = {}; fileSize.HighPart = fileAttributeData.nFileSizeHigh; fileSize.LowPart = fileAttributeData.nFileSizeLow; return static_cast<UInt64>(fileSize.QuadPart); } } return UInt64Max; }
static bool checkDirectoryExistance(const std::wstring& path) { WIN32_FILE_ATTRIBUTE_DATA fileData; if (GetFileAttributesExW(path.c_str(), GetFileExInfoStandard, &fileData) == 0) { // Failed to get attributes return false; } if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { return true; } return false; }
int __PHYSFS_platformIsDirectory(const char *fname) { int retval = 0; LPWSTR wpath; UTF8_TO_UNICODE_STACK_MACRO(wpath, fname); BAIL_IF_MACRO(wpath == NULL, ERR_OUT_OF_MEMORY, 0); //retval = ((pGetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY) != 0); WIN32_FILE_ATTRIBUTE_DATA file_info; const BOOL res = GetFileAttributesExW(wpath, GetFileExInfoStandard, &file_info); if (res) { retval = ((file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0); } __PHYSFS_smallFree(wpath); return(retval); } /* __PHYSFS_platformIsDirectory */