GW2DetermineFileTypeFromFile
GW2DetermineFileTypeFromFile 関数は、指定されたファイルのファイルタイプを判定します。 ファイルタイプを識別できない場合は、列挙型 ft_t の列挙定数 ft_unknown の値を返します。それ以外の場合は、ファイルタイプを示す列挙型 ft_t の値を返します。
- C++
- C#
- Java
- Python
- JavaScript
#include "glasswall.core2.api.h"
ft_t GW2DetermineFileTypeFromFile(const char *path);
パラメーター
path 検査するファイルの絶対ファイルパス。
戻り値
判定されたファイルタイプを示す列挙型 ft_t。ファイルタイプを判定できない場合は ft_unknown が返されます。
例
#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;
}
概要
/// <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)
戻り値
判定されたファイルタイプを示す値です。この関数で返される値と整合する列挙定数の一覧は、Cソースのヘッダーファイル filetype.h にあります。
概要
import com.glasswall.core2javabridge.*;
public int GW2DetermineFileTypeFromFile(String filePath) throws GlasswallException, NullPointerException
(Deprecated)
public int GW2DetermineFileTypeFromFile(byte[] BYTE) throws GlasswallException, NullPointerException
注
The GW2DetermineFileTypeFromFile function parameters have been updated to use String in place of byte[]. The original function has been deprecated.
戻り値
GW2DetermineFileTypeFromFile 関数は、Ft_t 型の列挙子を int に変換して返します。列挙定数の一覧は、Cソースのヘッダーファイル filetype.h にあります。
NullPointerException 例外は、filePath が null または空の場合にスローされます。
GlasswallException 例外は、filePath を取得できない場合にスローされます。
概要
指定された入力ファイルのファイルタイプを、整数識別子または文字列として判定します。
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.
"""
戻り値
判定されたファイルタイプを示す値または拡張子文字列です。この関数の戻り値と一致する列挙定数の一覧は、C ソースのヘッダーファイル filetype.h にあります。
概要
/**
* 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)
戻り値
判定されたファイルタイプを示す値です。この関数で返される値と整合する列挙定数の一覧は、Cソースのヘッダーファイル filetype.h にあります。