betrayed

Bulk File Renamer/Randomizer [VB.Net]

Jul 21st, 2021
1,014
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Threading, System.IO, System.Text
  2. Module Module1
  3.     Public path As String
  4.     Public i As Integer = 0
  5.     'Public rnd As New Random
  6.     Sub Main()
  7.         Console.Title = "Black Widow  -  Bulk File Renamer  -  V1.0"
  8.         Console.ForegroundColor = ConsoleColor.Red
  9.         Console.WriteLine("
  10.           /      \
  11.        \  \  ,,  /  /
  12.         '-.`\()/`.-'
  13.        .--_'(  )'_--.
  14.       / /` /`**`\ `\ \
  15.        |  |  ><  |  |
  16.        \  \      /  /
  17.            '.__.'  
  18.  
  19. Randomize filenames en-masse!
  20. ")
  21.         Console.ForegroundColor = ConsoleColor.Gray
  22.         Console.Write(" Enter in path to directory: ")
  23.         path = Console.ReadLine()
  24.  
  25.         Dim len As Integer = path.Length()
  26.         Dim chkSlash As String = path
  27.         chkSlash = chkSlash.Substring(len - 1)
  28.         If chkSlash.ToString = "/" Then
  29.             path = path.Remove(path.Length - 1)
  30.         End If
  31.  
  32.  
  33.         Console.WriteLine("
  34. Pending...
  35. ")
  36.         'Thread.Sleep(2000)
  37.  
  38.         For Each targFile In Directory.GetFiles(path)
  39.             Dim fileName As String = genJunk(5, 15)
  40.             'Thread.Sleep(500)
  41.  
  42.             Dim targInfo As New IO.FileInfo(targFile)
  43.             Dim fileExt As String = targInfo.Extension
  44.  
  45.             Do
  46.                 If My.Computer.FileSystem.FileExists(path + "\" + fileName + fileExt) Then
  47.                     fileName = fileName + i.ToString
  48.                 Else
  49.                     Exit Do
  50.                 End If
  51.             Loop
  52.  
  53.             Try
  54.                 My.Computer.FileSystem.RenameFile(targFile, fileName + fileExt)
  55.                 Console.WriteLine(targFile + " ---> " + fileName + fileExt)
  56.             Catch ex As Exception
  57.                 Console.WriteLine(" Critical error encountered!")
  58.             End Try
  59.  
  60.         Next
  61.         Console.WriteLine("
  62. Task completed! Strike ENTER to finalize.
  63. ")
  64.         Console.ReadLine()
  65.         Environment.Exit(0)
  66.     End Sub
  67.  
  68.     Public Function genJunk(MinLength As Integer, MaxLength As Integer) As String
  69.         Static rnd As New Random()
  70.         Dim validchars() As Char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ0123456789".ToCharArray()
  71.         Dim res As String = ""
  72.  
  73.         For i As Integer = 0 To rnd.Next(MinLength - 1, MaxLength)
  74.             res += validchars(rnd.Next(0, validchars.Length))
  75.         Next
  76.  
  77.         Return res
  78.     End Function
  79. End Module
  80.  
RAW Paste Data