GW2DetermineFileTypeFromFile
Hàm GW2DetermineFileTypeFromFile xác định loại tệp cho tệp đã cho. Nếu không thể nhận diện loại tệp, hàm sẽ trả về giá trị của hằng số liệt kê ft_unknown từ kiểu liệt kê ft_t; nếu không, hàm sẽ trả về một giá trị từ kiểu liệt kê ft_t biểu thị loại tệp.
- C++
- C#
- Java
- Python
- JavaScript
#include "glasswall.core2.api.h"
ft_t GW2DetermineFileTypeFromFile(const char *path);
Tham số
path Đường dẫn tệp tuyệt đối tới tệp bạn muốn kiểm tra.
Giá trị trả về
Kiểu liệt kê ft_t cho biết loại tệp đã được xác định. Nếu không thể xác định loại tệp thì ft_unknown sẽ được trả về.
Ví dụ
#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;
}
Tóm tắt
/// <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)
Giá trị trả về
Một giá trị cho biết loại tệp đã được xác định - Danh sách các hằng số liệt kê nằm trong tệp tiêu đề nguồn C filetype.h nhất quán với giá trị được trả về cho hàm này.
Tóm tắt
import com.glasswall.core2javabridge.*;
public int GW2DetermineFileTypeFromFile(String filePath) throws GlasswallException, NullPointerException
(Deprecated)
public int GW2DetermineFileTypeFromFile(byte[] BYTE) throws GlasswallException, NullPointerException
Lưu ý
Các tham số của hàm GW2DetermineFileTypeFromFile đã được cập nhật để sử dụng String thay cho byte[]. Hàm gốc đã bị deprecated.
Giá trị trả về
Hàm GW2DetermineFileTypeFromFile trả về một giá trị liệt kê kiểu Ft_t được chuyển đổi thành int. Danh sách các hằng số liệt kê có thể được tìm thấy trong tệp tiêu đề nguồn C filetype.h.
Một ngoại lệ NullPointerException sẽ được ném ra nếu filePath là null hoặc rỗng.
Một ngoại lệ GlasswallException sẽ được ném ra nếu không thể truy xuất filePath.
Tóm tắt
Xác định loại tệp của một tệp đầu vào nhất định, dưới dạng mã định danh số nguyên hoặc chuỗi.
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.
"""
Giá trị trả về
Một giá trị hoặc chuỗi phần mở rộng cho biết loại tệp đã được xác định - Danh sách các hằng số liệt kê trong tệp tiêu đề mã nguồn C filetype.h nhất quán với giá trị được trả về cho hàm này.
Tóm tắt
/**
* 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)
Giá trị trả về
Một giá trị cho biết loại tệp đã được xác định - Danh sách các hằng số liệt kê nằm trong tệp tiêu đề nguồn C filetype.h nhất quán với giá trị được trả về cho hàm này.