GW2DetermineFileTypeFromFile
ฟังก์ชัน GW2DetermineFileTypeFromFile ใช้ระบุประเภทไฟล์สำหรับไฟล์ที่กำหนด หากไม่สามารถแยกแยะประเภทไฟล์ได้ ฟังก์ชันจะส่งคืนค่าคงที่ของ enumeration ft_unknown จากชนิด enumeration ft_t ; มิฉะนั้น จะส่งคืนค่าจากชนิด enumeration ft_t ที่ระบุประเภทไฟล์
- C++
- C#
- Java
- Python
- JavaScript
#include "glasswall.core2.api.h"
ft_t GW2DetermineFileTypeFromFile(const char *path);
พารามิเตอร์
path พาธไฟล์แบบสัมบูรณ์ของไฟล์ที่คุณต้องการตรวจสอบ
ส่งกลับ
ชนิดข้อมูลแบบ enumerated 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)
ส่งกลับ
ค่าที่ระบุประเภทไฟล์ที่ตรวจพบ - รายการค่าคงที่ของ enumeration อยู่ในไฟล์ส่วนหัวซอร์ส C filetype.h ซึ่งสอดคล้องกับค่าที่ส่งคืนสำหรับฟังก์ชันนี้
สรุป
import com.glasswall.core2javabridge.*;
public int GW2DetermineFileTypeFromFile(String filePath) throws GlasswallException, NullPointerException
(Deprecated)
public int GW2DetermineFileTypeFromFile(byte[] BYTE) throws GlasswallException, NullPointerException
หมายเหตุ
พารามิเตอร์ของฟังก์ชัน GW2DetermineFileTypeFromFile ได้รับการอัปเดตให้ใช้ String แทน byte[] แล้ว ฟังก์ชันดั้งเดิมถูกเลิกใช้งานแล้ว
ส่งกลับ
ฟังก์ชัน GW2DetermineFileTypeFromFile ส่งคืนตัวแจงค่า (enumerator) ของชนิด Ft_t ที่แปลงเป็น int รายการค่าคงที่ของ enumeration สามารถดูได้ในไฟล์ส่วนหัวซอร์ส 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.
"""
ส่งกลับ
ค่าหรือสตริงนามสกุลที่ระบุประเภทไฟล์ที่ตรวจพบ - รายการค่าคงที่ของ enumeration อยู่ในไฟล์ส่วนหัวซอร์ส 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)
ส่งกลับ
ค่าที่ระบุประเภทไฟล์ที่ตรวจพบ - รายการค่าคงที่ของ enumeration อยู่ในไฟล์ส่วนหัวซอร์ส C filetype.h ซึ่งสอดคล้องกับค่าที่ส่งคืนสำหรับฟังก์ชันนี้