-- --Unique File Names -- --jxliv7@hotmail.com (jon) -- --uniquefilenames.e -- --Ver 1.1 -- --The created filename will be 8 characters long. --The filename character set is A-Z. --The intent is to be 8.3 compatible. --After looking at CChris's "unique_filename() function", I realized that -- if filenames were based upon time (consistently for any one -- application), then each filename would also be unique. --These unique filenames are based upon the Euphoria date() function, -- which means there can only be ONE unique filename per second. --If you need multiple files per second, use a "for" function to add -- characters to the end of the filename. --You could add a character(s) to the beginning or end of the filename, -- but this character set will only be unique every second. --You may also add any extension you choose (or none). --There are two caveats: you can't generate more than ONE filename per -- second, and a filename by the created name could possibly exist -- (although the possibly is rather remote). --Revised 2007-03-31 --Corrected error, used base 27 in calculations instead of 26. Oops. --Instead of a new filename every second, it was 25 seconds. --Thanks to c.k.lester for the bug report. --Comments, suggestions, questions, etc., are appreciated. -- global function UniqueFileNames() sequence Filename, curTime integer N, C, Tot Filename = "zzzzzzzz" --if there's a lower case "z" in the filename, -- there's an error curTime = date() N = 4 C = 390625 --390625 = 25^4. in base 26 A=0, B=2, .., Z=25 Tot = curTime[4]*3600 + curTime[5]*60 + curTime[6] --these are the elapsed seconds so far in the day Filename[1] = curTime[1] - 107 + 65 --2007 is 107 in date(), so the first character is -- "A" (ASCII 65) -- in 2008 it woud be a "B" --if you'd like, you could change this Filename[2] = floor(curTime[8]/25) Filename[3] = 65 + curTime[8] - (Filename[2] * 25) Filename[2] += 65 --curTime[8] is the day of year, 1 thru 365 or 366 --for example, day 1 = AB, 267 = JQ, and 365 = NO --this loop converts the time of day in seconds -- to a 5 digit, base 26 number while N-9 do Filename[N] = floor(Tot/C) Tot -= (Filename[N]*C) Filename[N] += 65 N += 1 C /= 25 end while return Filename --a unique 8 character filename using only A thru Z end function --