Methods (19)
Namespace: SchwabenCode.QuickIO.SafeNative
internal static classWin32SafeNativeMethodsCopyFileCreateDirectoryCreateFileDeleteFileFindCloseFindCloseFindFirstFileFindNextFileGetDiskFreeSpaceExGetFileAttributesGetFileSizeExLocalFreeMoveFileRemoveDirectorySetAllFileTimesSetCreationFileTimeSetFileAttributesSetLastAccessFileTimeSetLastWriteFileTime

Syntax

internal static class Win32SafeNativeMethods : object

Basetype

  • System.object

Summary

Native Methods - take a look on www.pinvoke.net

Methods

internal static Boolean CopyFile(String fullNameSource, String fullNameTarget, Boolean failOnExists)

Parameters

fullNameSource

String

The name of an existing file.

fullNameTarget

String

The name of the new file.

failOnExists

Boolean

If this parameter is TRUE and the new file specified by lpNewFileName already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.

Returns

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.

CreateDirectory(String fullName, IntPtr securityAttributes)

Creates a new directory. If the underlying file system supports security on files and directories, the function applies a specified security descriptor to the new directory.

internal static Boolean CreateDirectory(String fullName, IntPtr securityAttributes)

Parameters

fullName

String

The path of the directory to be created.

securityAttributes

IntPtr

Returns

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible errors include the following.

Remarks

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx

CreateFile(String fullName, FileAccess dwDesiredAccess, FileShare dwShareMode, IntPtr lpSecurityAttributes, FileMode dwCreationDisposition, FileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile)

Creates or opens a file or I/O device. The most commonly used I/O devices are as follows: file, file stream, directory, physical disk, volume, console buffer, tape drive, communications resource, mailslot, and pipe. The function returns a handle that can be used to access the file or device for various types of I/O depending on the file or device and the flags and attributes specified.

internal static SafeFileHandle CreateFile(String fullName, FileAccess dwDesiredAccess, FileShare dwShareMode, IntPtr lpSecurityAttributes, FileMode dwCreationDisposition, FileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile)

Parameters

fullName

String

The name of the file or device to be created or opened.

dwDesiredAccess

FileAccess

The requested access to the file or device, which can be summarized as read, write, both or neither zero).

dwShareMode

FileShare

The requested sharing mode of the file or device, which can be read, write, both, delete, all of these, or none (refer to the following table).

lpSecurityAttributes

IntPtr

A pointer to a SECURITY_ATTRIBUTES structure that contains two separate but related data members: an optional security descriptor, and a Boolean value that determines whether the returned handle can be inherited by child processes. This parameter can be NULL.

dwCreationDisposition

FileMode

An action to take on a file or device that exists or does not exist.

dwFlagsAndAttributes

FileAttributes

The file or device attributes and flags, FILEATTRIBUTENORMAL being the most common default value for files.

hTemplateFile

IntPtr

A valid handle to a template file with the GENERIC_READ access right. The template file supplies file attributes and extended attributes for the file that is being created

Returns

SafeFileHandle

Remarks

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx

internal static Boolean DeleteFile(String fullName)

Parameters

fullName

String

Returns

Returns true on success, false on error Win32Exception

FindClose(Win32FindData win32FindData)

Closes a file search handle opened by the FindFirstFile, FindFirstFileEx, FindFirstFileNameW, FindFirstFileNameTransactedW, FindFirstFileTransacted, FindFirstStreamTransactedW, or FindFirstStreamW functions.

internal static Boolean FindClose(Win32FindData win32FindData)

Parameters

win32FindData

Win32FindData

The file search handle.

Returns

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

FindClose(SafeHandle findFile)

Closes a file search handle opened by the FindFirstFile, FindFirstFileEx, FindFirstFileNameW, FindFirstFileNameTransactedW, FindFirstFileTransacted, FindFirstStreamTransactedW, or FindFirstStreamW functions.

internal static Boolean FindClose(SafeHandle findFile)

Parameters

findFile

SafeHandle

The file search handle.

Returns

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

FindFirstFile(String fullName, Win32FindData win32FindData)

Searches a directory for a file or subdirectory with a name that matches a specific name (or partial name if wildcards are used).

internal static Win32FileHandle FindFirstFile(String fullName, Win32FindData win32FindData)

Parameters

fullName

String

The directory or path, and the file name, which can include wildcard characters, for example, an asterisk (*) or a question mark (?).

win32FindData

Win32FindData

A pointer to the Win32FileHandle structure that receives information about a found file or directory.

Returns

If the function succeeds, the return value is a search handle used in a subsequent call to FindNextFile or FindClose, and the lpFindFileData parameter contains information about the first file or directory found.

If the function fails or fails to locate files from the search string in the lpFileName parameter, the return value is INVALIDHANDLEVALUE and the contents of lpFindFileData are indeterminate. To get extended error information, call the GetLastError function.

If the function fails because no matching files can be found, the GetLastError function returns ERRORFILENOT_FOUND.

FindNextFile(Win32FileHandle findFileHandle, Win32FindData findData)

Continues a file search from a previous call to the FindFirstFile

internal static Boolean FindNextFile(Win32FileHandle findFileHandle, Win32FindData findData)

Parameters

findFileHandle

Win32FileHandle

The search handle returned by a previous call to the FindFirstFile or FindFirstFileEx function.

findData

Win32FindData

A pointer to the Win32FindData structure that receives information about the found file or subdirectory.

Returns

If the function succeeds, the return value is nonzero and the lpFindFileData parameter contains information about the next file or directory found. If the function fails, the return value is zero and the contents of lpFindFileData are indeterminate. To get extended error information, call the GetLastError function. If the function fails because no more matching files can be found, the GetLastError function returns ERRORNOMORE_FILES.

internal static Boolean GetDiskFreeSpaceEx(String fullName, UInt64& freeBytesAvailable, UInt64& totalNumberOfBytes, UInt64& totalNumberOfFreeBytes)

GetFileAttributes(String fullName)

Retrieves file system attributes for a specified file or directory.

internal static UInt32 GetFileAttributes(String fullName)

Parameters

fullName

String

The name of the file or directory.

Returns

Returns bits of attributes or DOWRD-1 (0xffffffff => UInt32.Max on error)

GetFileSizeEx(SafeHandle hFile, Int64& lpFileSize)

Retrieves the size of the specified file.

internal static Boolean GetFileSizeEx(SafeHandle hFile, Int64& lpFileSize)

Parameters

hFile

SafeHandle

A handle to the file. The handle must have been created with either the GENERICREAD or GENERICWRITE access right or equivalent.

lpFileSize

Int64&

A pointer to a LARGE_INTEGER structure that receives the file size, in bytes.

Returns

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

LocalFree(IntPtr handle)

Frees the specified local memory object and invalidates its handle.

internal static IntPtr LocalFree(IntPtr handle)

Parameters

handle

IntPtr

A handle to the local memory object.

Returns

If the function succeeds, the return value is NULL.

If the function fails, the return value is equal to a handle to the local memory object. To get extended error information, call GetLastError.

MoveFile(String fullNameSource, String fullNameTarget)

Moves an existing file or a directory, including its children.

internal static Boolean MoveFile(String fullNameSource, String fullNameTarget)

Parameters

fullNameSource

String

The current name of the file or directory on the local computer.

fullNameTarget

String

The new name for the file or directory. The new name must not already exist. A new file may be on a different file system or drive. A new directory must be on the same drive.

Returns

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.

RemoveDirectory(String fullName)

Removes a directory.

internal static Boolean RemoveDirectory(String fullName)

Parameters

fullName

String

Returns

Returns true on success, false on error Win32Exception

internal static Boolean SetAllFileTimes(Win32FindData hFile, Int64& lpCreationTime, Int64& lpLastAccessTime, Int64& lpLastWriteTime)
internal static Boolean SetCreationFileTime(Win32FindData hFile, Int64& lpCreationTime, IntPtr lpLastAccessTime, IntPtr lpLastWriteTime)
internal static Boolean SetFileAttributes(String fullName, UInt32 fileAttributes)

Parameters

fullName

String

Path to the entry

fileAttributes

UInt32

Attributes

Returns

Returns true on success, false on error Win32Exception

internal static Boolean SetLastAccessFileTime(Win32FindData hFile, IntPtr lpCreationTime, Int64& lpLastAccessTime, IntPtr lpLastWriteTime)
internal static Boolean SetLastWriteFileTime(Win32FindData hFile, IntPtr lpCreationTime, IntPtr lpLastAccessTime, Int64& lpLastWriteTime)