IMVU Product Chkn Name Randomizer

DataMine
by DataMine · 2 posts
1 year ago in Autoit
Posted 1 year ago · Author
IMVU Product Chkn Name Randomizer
This script will give all chkns in a specific folder a randomized 10 character name. It will also generate a text file that lists what each chkn was renamed to in case you need to restore the chkn's original name.

Code
#include <Array.au3>
#include <File.au3>

;The directory to search in
Global $sWorkingDirectory = "C:\Users\User\Desktop\New folder"
Global $sHistoryFileName = "chkn renamer history.txt"
Global $sHistoryFilePath = $sWorkingDirectory & "\" & $sHistoryFileName
;Create an array of ASCII codes to generate the string from.
;We do this rather than using Chr(Random(num,num,1)) because
;this is less work
Global $aAvailableCharacters = StringToASCIIArray("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
Const $iNewNameLength = 10

If Not FileExists($sWorkingDirectory) Then
   MsgBox($MB_ICONERROR, "Error", "The working directory is missing.")
   Exit
EndIF

;Create an array of all the CHKNs found in the working directory
$aChknArray = _FileListToArray($sWorkingDirectory, "*.chkn")

;If no CHKNs were found
If @error = 4 Then
   MsgBox($MB_ICONERROR, "Error", "No CHKNs were found.")
   Exit
EndIf

Local $hFileOpen = FileOpen($sHistoryFilePath, $FO_APPEND)

For $i = 1 to $aChknArray[0]
   Local $sNewName = GenerateRandomName()
   FileMove($sWorkingDirectory & "\" & $aChknArray[$i], $sWorkingDirectory & "\" & $sNewName & ".chkn")
   $sHistoryLine = $aChknArray[$i] & " was renamed to " & $sNewName & ".chkn"
   ConsoleWrite($sHistoryLine & @LF);
   FileWrite($hFileOpen, $sHistoryLine & @CRLF)
Next

Func GenerateRandomName()
   Local $sNewName = ""

   For $i = 1 To $iNewNameLength
     Local $sPreviousCharacter = ""

     ;Create a variable to store the chosen character and give it a value
     ;by selecting a random ASCII code from the $aAvailableCharacters array And
     ;converting it to a character
     Local $sSelectedCharacter = Chr($aAvailableCharacters[Random(1, UBound($aAvailableCharacters))])

     ;prevent duplicate characters side-by-side by repeatedly generating a new character
     ;using the same technique as above until a unique one is found
     Do
       $sSelectedCharacter = Chr($aAvailableCharacters[Random(1, UBound($aAvailableCharacters))])
     Until Not ($sSelectedCharacter = $sPreviousCharacter)

     $sPreviousCharacter = $sSelectedCharacter
     $sNewName &= $sSelectedCharacter
   Next

   Return $sNewName
EndFunc


How do I use this script?

To learn how to use these scripts, see my tutorial on compiling AutoIT scripts here: viewtopic.php?f=113&t=12150

Create an account or sign in to comment

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

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

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

REGISTER A NEW ACCOUNT