GW2DetermineFileTypeFromFile
Tinutukoy ng function na GW2DetermineFileTypeFromFile ang uri ng file para sa ibinigay na file. Kung hindi nito matukoy ang uri ng file, ibinabalik nito ang halaga ng enumeration constant na ft_unknown mula sa enumerated type na ft_t ; kung hindi, ibinabalik nito ang isang halaga mula sa enumerated type na ft_t na nagsasaad ng uri ng file.
- C++
- C#
- Java
- Python
- JavaScript
#include "glasswall.core2.api.h"
ft_t GW2DetermineFileTypeFromFile(const char *path);
Mga Parameter
path Ang absolute file path patungo sa file na nais mong suriin.
Ibinabalik
Enumerated type na ft_t na nagsasaad ng natukoy na uri ng file. Kung hindi matukoy ang uri ng file, ibabalik ang ft_unknown.
Halimbawa
#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;
}
Buod
/// <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)
Ibinabalik
Isang halagang nagsasaad ng natukoy na uri ng file - Ang listahan ng mga enumeration constant ay nasa C source header file na filetype.h at tumutugma sa ibinalik na halaga para sa function na ito.
Buod
import com.glasswall.core2javabridge.*;
public int GW2DetermineFileTypeFromFile(String filePath) throws GlasswallException, NullPointerException
(Deprecated)
public int GW2DetermineFileTypeFromFile(byte[] BYTE) throws GlasswallException, NullPointerException
Tandaan
Na-update ang mga parameter ng function na GW2DetermineFileTypeFromFile upang gamitin ang String kapalit ng byte[]. Ang orihinal na function ay deprecated na.
Ibinabalik
Ang function na GW2DetermineFileTypeFromFile ay nagbabalik ng enumerator na may uring Ft_t na kino-convert sa isang int. Ang listahan ng mga enumeration constant ay makikita sa C source header file na filetype.h.
Isang NullPointerException exception ang ihahagis kung ang filePath ay null o walang laman.
Isang GlasswallException exception ang ihahagis kung ang filePath ay hindi makuha.
Buod
Tukuyin ang uri ng file ng ibinigay na input file, alinman bilang integer identifier o 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.
"""
Ibinabalik
Isang value o extension string na nagsasaad ng natukoy na uri ng file - Ang listahan ng mga enumeration constant ay nasa C source header file na filetype.h at tumutugma sa ibinalik na value para sa function na ito.
Buod
/**
* 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)
Ibinabalik
Isang halagang nagsasaad ng natukoy na uri ng file - Ang listahan ng mga enumeration constant ay nasa C source header file na filetype.h at tumutugma sa ibinalik na halaga para sa function na ito.