GW2DetermineFileTypeFromFile

Prev Next

The GW2DetermineFileTypeFromFile function determines the file type for the given file. If it cannot discern the file type, it returns the value of the enumeration constant ft_unkown; otherwise, it returns a value from the enumerated type ft_t indicating the file type.


#include "glasswall.core2.api.h"
ft_t GW2DetermineFileTypeFromFile(const char *path);

Parameters

โ€ƒ path The absolute file path to the file you wish to examine.

Returns

โ€ƒ Enumerated type 'ft_t' indicating the determined file type. If the file type cannot be determined then 'ft_unkown' will be returned

Example

#include "glasswall.core2.api.h"
#include โ€œfiletype.hโ€

ft_t file_type = GW2DetermineFileTypeFromFile("c:\\dir1\\dir2\\filename");
char *type = NULL;
switch (file_type)   /* categorise them */
{
    case ft_doc:
    case ft_docx:
    case ft_ppt:
    case ft_pptx:
    case ft_xls:
    case ft_xlsx:
        type = "Microsoft Office";
        break;

    case ft_png:
    case ft_jpg:
    case ft_gif:
    case ft_tiff:
        type = "Image file";
        break;

    case ft_pdf:
        type = "PDF";
        break;

    default:
        type = "Unrecognised file type";
        break;
}

Synopsis

/// <summary>
/// Returns a value indicating the the file type from an input file by Glasswall.
/// </summary>
/// <param name="inputFilePathName">The file path to the input file</param>
/// <returns>A value indicating the determined file type </returns>
public int DetermineFileTypeFromFile(string inputFilePathName)

Returns

A value indicating the determined file type - A list of the enumeration constants is in the C source header file filetype.h are consistent with the returned value for this function.

Synopsis

import com.glasswall.core2javabridge.*;

public int GW2DetermineFileTypeFromFile(String filePath) throws GlasswallException, NullPointerException

(Deprecated) 
public int GW2DetermineFileTypeFromFile(byte[] BYTE) throws GlasswallException, NullPointerException

Note: 

The GW2DetermineFileTypeFromFile function parameters have been updated to use String in place of byte[]. The original function has been deprecated.

Returns

The GW2DetermineFileTypeFromFile function returns an enumerator of type Ft_t converted to an int. A list of the enumeration constants may be found in the C source header file filetype.h.

A NullPointerException exception will be thrown if filePath is null or empty.

A GlasswallException exception will be thrown if filePath cannot be retrieved.

Synopsis

Determine the file type of a given input file, either as an integer identifier or a string.

def determine_file_type(self, input_file: Union[str, bytes, bytearray, io.BytesIO], as_string: bool = False, raise_unsupported: bool = True) -> Union[int, str]:
    """ Determine the file type of a given input file, either as an integer identifier or a string.

    Args:
        input_file (Union[str, bytes, bytearray, io.BytesIO]): The input file to analyse. It can be provided as a file path (str), bytes, bytearray, or a BytesIO object.
        as_string (bool, optional): Return file type as string, eg: "bmp" instead of: 29. Defaults to False.
        raise_unsupported (bool, optional): Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

    Returns:
        file_type (Union[int, str]): The file type.
    """

Returns

A value or extension string indicating the determined file type - A list of the enumeration constants is in the C source header file filetype.h are consistent with the returned value for this function.

Synopsis

/**
 * This function determines the file type for a given file provided it is supported by Glasswall. Notice this is not related to a session.
 * @param {string} path The path to the provided file.
 * @returns {number} The determined file type, as enumerated in the C source header file filetype.h.
 */

GW2DetermineFileTypeFromFile(path)

Returns

A value indicating the determined file type - A list of the enumeration constants is in the C source header file filetypes.h are consistent with the returned value for this function.