Skip navigation

Redid the File Renamer script for you based on what you asked for. This should tag common video files as v and pictures (well everything that isn’t excluded) as p.  I also added a file browser to the script as well as a general graphical interface to kind of make things simpler.  If you don’t want it in there I can easily strip it out and put it back to command line.

<#---------------------------------------------------------------------
Script: Renamer.ps1
Author: Daniel Belcher
Modified: 11/5/11
---------------------------------------------------------------------#>
FUNCTION Folder($MSG, $PATH) { 
    $SHELL = New-Object -comObject Shell.Application  
	$FOLDER = $SHELL.BrowseForFolder(0, $MSG, 0, $PATH)
	    if ($FOLDER -ne $NULL) 
			{$FOLDER.self.Path}
} 
	FUNCTION Message($MSG, $TITLE) {
		$SHELL = New-Object -ComObject Wscript.Shell
		$SHELL.Popup($MSG,0,$TITLE,1)
		}
<#---------------------------------------------------------------------
Select Folder with contnets to modify via Shell.Application namespace
and verify that the choice is correct with Wscript popup method.
---------------------------------------------------------------------#>
   $FOLDER = Folder -MSG "Select your folder..." -Path .\
if($FOLDER -eq $NULL) {
Message -MSG "Must select a folder to continue." -Title "Error" 
		break}
$VERIFY = (Message `
"You Selected:
$Folder
Its contents will be renamed, are you sure?" -Title "Verify")
	if($VERIFY -eq "2") {break}
<#---------------------------------------------------------------------
Grab directory contents and process
---------------------------------------------------------------------#>
	$LIST = Get-ChildItem "$FOLDER\*" -Exclude `
	*ps1,*exe,*mp3,*dll,*ini,*cfg,*ocx,*doc?,*xls?,*txt|Sort-Object lastwritetime
			$X = 0
	ForEach($OBJECT in $LIST)
		{$EXTENSION = $OBJECT.ToString().Split("\") | Select -Last 1; 
		$EXTENSION = $EXTENSION.Split(".") | Select-Object -Last 1
	if($EXTENSION.Contains("ps1") -eq $TRUE){break}
$TYPE = "p"
		switch($EXTENSION){
			mov{$TYPE = "v"}
			avi{$TYPE = "v"}
			wmv{$TYPE = "v"}
			mpg{$TYPE = "v"}
			mpeg{$TYPE = "v"}
			}
			$FILEINFO = New-Object System.IO.DirectoryInfo($OBJECT)
				$NAME = $FILEINFO.LastWriteTime.GetDateTimeFormats() |`
					Select-Object -Index 99
				$NAME = "$($NAME) ($($X)) $($TYPE).$($EXTENSION)"
						Write-Output $NAME
			Rename-Item -Path "$OBJECT" $NAME
			$X = $X+1
			}
<#---------------------------------------------------------------------
END
---------------------------------------------------------------------#>

#.

Feel free to modify this anyway you like, add more extensions, exclude more etc. This was kind of a lazy hack to get you what you told me, and I had a few minutes to kill since I couldn’t sleep tonight.

Leave a Reply