This built-in predicate retrieves the next file from a specified directory and creates a structure with information about the file. The name of the directory may contain wildcard characters like ? and *. The directory to scan is the first argument. If the next file was found then the predicate is exited, after all files have been found the predicate fails. The format of the created file information structure is:
info_f( path_of_file, hidden, readonly, create(date(y, m, d), time(h, m, s)), modified(date(y, m, d), time(h, m, s)), size_of_file ).
see also: app_dir/1 base64_decode_file/2 base64_encode_file/2 compress_file/2 copy_file/2 current_dir/1 decompress_file/1 decompress_file/2 decrypt_file/3 delete_file/1 encrypt_file/3 exists_dir/1 exists_file/1 make_dir/1 md5_file/2 next_file/2 next_file/3 next_dir/2 remove_dir/1 rename_file/2 set_current_dir/1 split_fn/2 unlink_file/1 wipe_file/1
| Examples of f_info structure |
| info_f('c:\prj\report.txt', false, false, create(date(2000, 7, 6), time(13, 11, 5)), modified(date(2000, 7, 14), time(17, 40, 32)), 21920)). |
| info_f('c:\hidden.sys', true, true, create(date(1980, 1, 1), time(2, 0, 0)), modified(date(2000, 6, 27), time(16, 38, 18)), 156496) |
| Examples | |
| info_file('c:\\prj\\report.txt', Properties). | If the specified file exists then a f_info structure (like the first row in the table above) was matched with the empty variable Properties. |
| info_file('c:\\prj\\report.txt', info_f(Name, false, false, C, M, S)). | If the specified file exists then the following bindings will
exist after the predicate has exited: Name = 'c:\prj\report.txt' C = create(date(2000, 7, 6), time(13, 11, 5)) M = modified(date(2000, 7, 14), time(17, 40, 32)) S = 21920 |
| info_file('c:\\prj\\*.*', something_else). | The predicate fails because for each file in the directory 'c:\prj\' a f_info structure is created and this is always a mismatch with the second argument. |
| Exceptions | |
| The first argument is an empty variable | an instantiation_error exception is thrown |
| The first argument Directory is not an atom enclosed by single or double quotes | A type_error(atom_singlequotes, Directory) exception is thrown |
| The second argument is not a variable and the specified File does not exist | An existence_error(file, File) exception is thrown |