Skip to content

Instantly share code, notes, and snippets.

@WildDogOne
Created November 9, 2013 14:46
Show Gist options
  • Save WildDogOne/7386225 to your computer and use it in GitHub Desktop.
Save WildDogOne/7386225 to your computer and use it in GitHub Desktop.
cls
#Konstanten
$location = "F:\Images\Grabber"
$sites = @("konachan.com","e621.net","danbooru.donmai.us","gelbooru.com","wildcritters.ws","yande.re")
$maxPath = 260
$files = Get-ChildItem -Recurse $location | Where {$_.psIsContainer -eq $false}
foreach ($file in $files)
{
$ok = 0
foreach ($site in $sites){
if ($file.Name.StartsWith($site,"CurrentCultureIgnoreCase") -eq $true)
{
$ok = 1
}
}
if($ok -eq 0){
foreach ($site in $sites)
{
if ($file.Name.StartsWith($site.Substring(0,1),"CurrentCultureIgnoreCase") -eq $true)
{
if ($file.name -match "^.*\s\d{6}\s"){
Write-Host -BackgroundColor black -ForegroundColor yellow "################################"
$file.Name
$newname = $file.BaseName -replace "(^\S*).","$site "
$newname = $newname.TrimEnd(" ")
$t =1
while ($t -eq 1){
if ($newname.Length -ge ($maxPath - $file.DirectoryName.Length))
{
#$newname = $newname.Substring(0,205)
$newname = $newname -replace "\s[^\s]*$",""
}
else
{
$newname = $newname + $file.Extension
$t = 0
}
}
$newname
Rename-Item $file.FullName $newname
#exit
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment