This built-in predicate retrieves the next file from a specified directory. The name of the directory may contain wildcard characters like ? and *. The directory to scan is the first argument. The second argument is matched with the next file in the directory. If the next file was found then the predicate is exited, after all files have been found the predicate fails.
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 info_file/2 make_dir/1 md5_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 | |
| next_file('c:\\documents\\*.tdt', File). | If the specified directory does not contain any files with the extension 'tdt' then the predicate fails. |
| next_file('c:\\documents\\*.*', File). | The name of each file in the folder 'c:\documents\' is matched with the argument File. |
| next_file('c:\\documents\\*.*', 'mydoc.txt'). | If the name of the first file in the folder 'c:\documents\' is 'mydoc.txt' then this predicate is exited, else it fails. The path of the file is not included in the name of the file found. |
| 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 FileName is neither a variable nor an atom enclosed by single or double quotes | A type_error(atom_singlequotes, FileName) exception is thrown |