[eggPlant Functional] Dynamically Creating and Naming a File

The example below is fairly simple and can be adapted to fit your needs. It uses a couple of provided ranges to randomly generate a file name at run time, and then create a file with that name. This approach is useful when conducting randomized tests or saving multiple files during run time.

//CREATING A FILE WITH A DYNAMICALLY GENERATED NAME\\
#This creates an empty file with a random five-character name. This method can be adapted to name files of various types#

Put "~/Temp/" into Path -- specify a file path

put a..z as list into alphas -- create a range of letters
put 1..5 as list into nums -- create a range of numbers

put (any item of alphas for each item of nums) joined by empty into Name -- Dynamically create the name using "Any". Note that this initially creates a list, but then joins the items of the list with "empty", creating a string from the list items, and storing that in the variable "Name".

put path & Name into filePath -- store the path and name into a fully assembled file path
put filePath & ".txt" into myFile -- assemble the file with file extension
if there is not a file myFile then -- check to make sure the file does not already exist before creating it
	create file myFile -- create the file
	log "Created file " & myFile -- log a message that the file was created, as well as its full path
end if