This topic has not yet been rated - Rate this topic

GetFileType function

Applies to: desktop apps only

Retrieves the file type of the specified file.

Syntax

DWORD WINAPI GetFileType(
  __in  HANDLE hFile
);

Parameters

hFile [in]

A handle to the file.

Return value

The function returns one of the following values.

Return code/valueDescription
FILE_TYPE_CHAR
0x0002

The specified file is a character file, typically an LPT device or a console.

FILE_TYPE_DISK
0x0001

The specified file is a disk file.

FILE_TYPE_PIPE
0x0003

The specified file is a socket, a named pipe, or an anonymous pipe.

FILE_TYPE_REMOTE
0x8000

Unused.

FILE_TYPE_UNKNOWN
0x0000

Either the type of the specified file is unknown, or the function failed.

 

You can distinguish between a "valid" return of FILE_TYPE_UNKNOWN and its return due to a calling error (for example, passing an invalid handle to GetFileType) by calling GetLastError.

If the function worked properly and FILE_TYPE_UNKNOWN was returned, a call to GetLastError will return NO_ERROR.

If the function returned FILE_TYPE_UNKNOWN due to an error in calling GetFileType, GetLastError will return the error code.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

FileAPI.h (include Windows.h);
WinBase.h on Windows Server 2008 R2, Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

File Management Functions
GetFileSize
GetFileTime

 

 

Send comments about this topic to Microsoft

Build date: 4/17/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Re: Hangs
You function hangs on duplicate handle possibly because of this: http://blogs.msdn.com/b/oldnewthing/archive/2011/12/02/10243553.aspx
C# syntax
[DllImport("kernel32.dll")]
internal static extern int GetFileType(SafeFileHandle handle);
vb.net syntax
<DllImport("kernel32.dll")> _
Public Shared Function GetFileType(ByVal handle As SafeFileHandle) As Integer End Function
Hangs
This hangs when using duplicate handle on an unknown handle value my guess is it's hanging on named pipe handles.