Add random number prefix to filename

From roonics
Revision as of 15:30, 27 October 2019 by Jlambert (talk | contribs) (Created page with "This allows you to add a randomly generated number to the prefix of a bunch of files. In the below example we are adding a random prefix to every *.jpg file: <pre> $files =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This allows you to add a randomly generated number to the prefix of a bunch of files.

In the below example we are adding a random prefix to every *.jpg file:

$files = Get-ChildItem "C:\temp\files" -Filter *.jpg
foreach ($file in $files) {
	$prefix = Get-Random
	$newFileName = "${prefix}_${file}"
	Rename-Item $file $newFileName
}