Returns a random folder name or file name.
Public Shared Function GetRandomFileName As String
Dim returnValue As String returnValue = Path.GetRandomFileName()
public static string GetRandomFileName()
public: static String^ GetRandomFileName()
public static function GetRandomFileName() : String
The GetRandomFileName method returns a cryptographically strong, random string that can be used as either a folder name or a file name. Unlike GetTempFileName, GetRandomFileName does not create a file. When the security of your file system is paramount, this method should be used instead of GetTempFileName.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
# get-randomfilename.ps1# Gets a random filename# Thomas Lee - tfl@psp.co.uk # Get two random file names:$fn1 = [system.io.path]::getrandomfilename()$fn2 = [system.io.path]::getrandomfilename()# Display Results"Random file name 1: {0}" -f $fn1"Random file name 2: {0}" -f $fn2A
This script produces the following output (NB: file names produced varies each time the script is run!)
PSH [C:\foo]: C:\foo\get-randomfilename.ps1Random file name 1: jfy0j0gs.abhRandom file name 2: g4hpusfo.lbd
The statement above ought to be removed from MSDN documentation. The GetRandomFilename method has nothing to do with the security of your file system, and promoting so would not only be bad practice but is insecure and ultimately wrong.