getUniqueFile method
Get a new random and unique filename in this Directory, and create a new File with that name.
-
length
- The length of the unique filename. The total length of the name of the returned file islength + (prefix?.length ?? 0) + (extension?.length ?? 0)
. -
maxTries
- How many times a new filename should be generated until a unique one is found in the Directory. If this parameter is set to null, then new filenames will be generated until a unique one is found. If this parameter is set to a fixed number and no unique name can be found, then an OutOfTriesException gets thrown. -
prefix
- The prefix for the unique filename. -
extension
- The file extension.
See also getUniqueFileSync
Implementation
Future<File> getUniqueFile({
int length = 30,
int? maxTries,
String? prefix,
String? extension,
lib_path.Context? pathContext,
FileFactory factory = File.new,
}) async {
pathContext ??= lib_path.context;
final names = await get_unique_file_impl.getNamesInDir(
directory: this,
pathContext: pathContext,
);
return get_unique_file_impl.getUniqueFile(
currentDir: this,
length: length,
maxTries: maxTries,
factory: factory,
namesInDir: names,
pathContext: pathContext,
extension: extension,
prefix: prefix,
);
}