Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Random TempFile Name Generator

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,28415
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Random TempFile Name Generator
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Random TempFile Name Generator - 11/29/2005 2:17:43 AM   
  DiGiTAL.SkReAM


Posts: 1139
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
This script can be used to generate a random temp filename, and can be easily converted into a function or subroutine for use in a larger script.

'==========================================================================
'
' NAME: Make_Temp_FileName.vbs
'
' AUTHOR: DiGiTAL.SkReAM
' DATE  : 11/28/2005
'
' COMMENT: To create a randomly generated temp filename
'
'==========================================================================
Option Explicit
Dim iFilenameCharacters, iHighestASCiiValue, iLowestASCiiValue
Dim iCharASCiiValue, sTmpFileName, sTmpFile, oShell
Set oShell = CreateObject("Wscript.Shell")
iFilenameCharacters = 8
iHighestASCiiValue = 126
iLowestASCiiValue = 46
sTmpFile = ""
sTmpFileName = ""
Do
    Randomize
    iCharASCiiValue = Int(((iHighestASCiiValue - iLowestASCiiValue + 1) * Rnd) + iLowestASCiiValue)  
     'Only want characters "a-z", "A-Z", "0-9", tilde, underscore, and period
     Select Case True
      Case iCharASCiiValue = 47
       'Filtered character
      Case iCharASCiiValue > 57 And iCharASCiiValue < 65
       'Filtered characters
      Case iCharASCiiValue > 89 And iCharASCiiValue < 95
       'Filtered characters
      Case iCharASCiiValue = 96
       'Filtered character
      Case iCharASCiiValue > 122 And iCharASCiiValue < 126
       'Filtered characters
      Case Else
       'Allow anything else in range
       sTmpFileName = sTmpFileName & Chr(iCharASCiiValue)
     End Select
Loop While Len(sTmpFileName) < iFilenameCharacters
sTmpFile = oShell.ExpandEnvironmentStrings("%TEMP%") & "\" & sTmpFileName & ".tmp"
WScript.Echo sTmpFile


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury
 
 
Post #: 1
 
 RE: Random TempFile Name Generator - 11/29/2005 7:33:43 AM   
  mbouchard


Posts: 1851
Score: 14
Joined: 5/15/2003
From: USA
Status: online
Very nice, where were you on Friday when I was trying to get something just like this working?

If you don't mind one suggestion to help make it a bit more "streamlined", instead of using Select Case with the filters, use a single If/Then. 

Ex.
Do
    Randomize
    strASC = Int(((iHighestASCiiValue - iLowestASCiiValue + 1) * Rnd) + iLowestASCiiValue)  
If (strASC > 47 AND strASC < 58) OR (strASC > 64 AND strASC < 91) OR (strASC > 96 AND strASC < 123) then
       sTmpFileName = sTmpFileName & Chr(strASC)
End If
Loop While Len(sTmpFileName) < iFilenameCharacters
msgbox sTmpFileName

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Random TempFile Name Generator Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts