Sign in to follow this  
Followers 0
graham

fn() to generate a randomly named temp file

1 post in this topic

#1 ·  Posted (edited)

Sometimes you want a temp scratch file & want to be sure that it does not exist...

;===============================================================================

;

; Description: Generates a Fully qualified path of a temporary file, guaranteed not to exist

; Syntax: _GetTempFileName ($prefix, $drive, $directory, $extension)

; Parameter(s): IN - $drive, $directory, $extension - if specified, will be

; used in the generated full path, if blank, will be filled

; in from @TempDir. The file name part is always generated

; and consists numbers preceded by the $prefix parameter,

; if any.

; Requirement(s): None

; Return Value(s): Fully qualified path of a temporary file, guaranteed not to

;

; Author(s): Graham Keellings software@Keellings.com

; Note(s): None

;

;===============================================================================

Func _GetTempFileName ($prefix, $drive, $directory, $extension)

Local $szDrive, $szDir, $szFName, $szExt, $fullPath

_SplitPath(@TempDir & "\dummy.tmp", $szDrive, $szDir, $szFName, $szExt)

if $drive <> "" then

$szDrive = $drive

endif

if $directory <> "" then

$szDir = $directory

endif

if $extension <> "" then

$szExt = $extension

endif

do

$fullPath = _MakePath($fullPath, $szDrive, $szDir, _

$prefix & Int(Random(1000000, 9999999)), $szExt)

until FileExists($fullPath) = 0

return $fullPath

EndFunc

Edited by graham

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0