例1
*获取文件夹下所有路径
get_system (‘example_dir’,HalconExamples)
ExampleDir:=HalconExamples+’\hdevelop’
list_files (ExampleDir, [‘files’,‘recursive’], Files)
*判断文件是否存在
dev_close_window ()
dev_open_window (0, 0, 512, 512, ‘black’, WindowHandle)
filename:=‘111.jpg’
file_exists (filename, FileExists)
if (FileExists)
disp_message (WindowHandle, ‘文件存在’, HalconExamples, 12, 12, ‘black’, ‘true’)
else
disp_message (WindowHandle, ‘文件不存在’, HalconExamples, 12, 12, ‘black’, ‘true’)
endif
例2
read_image (Image, ‘printer_chip/printer_chip_01’)
threshold (Image, Region, 128, 255)
area_center (Region, Area, Row, Column)
*向文本写入字符串
open_file (‘area.txt’, ‘output’, FileHandle)
fwrite_string (FileHandle, ‘面积是:’+Area)
close_file (FileHandle)
*读取文本
open_file (‘area.txt’, ‘input’, FileHandle)
fread_string (FileHandle, OutString, IsEOF)
close_file (FileHandle)