Aqui está a versão do PowerShell. Funciona para a pasta única, usa o regex para corresponder aos nomes dos arquivos. Apenas edite $OrigFolder
/ $NewFolder
de acordo:
# Folder where files are stored
$OrigFolder = 'C:\MyFolder'
# Folder where sorted files will be stored.
# It will be created if not exists.
$NewFolder = 'C:\MyFolder_Sorted'
# Folder, where files with empty part of the name will be stored
# Example: file "(1992)(Domark)(FR)(Disk 2 of 2)[construction kit].adf"
# will be moved to ".\Sorted\Unknown" folder
$UnknownFolder = 'Unknown'
# Regex to match filenames
$Regex = '^\s*(.*?)\s*\('
# Loop through files in directory, skip folders
Get-ChildItem -LiteralPath $OrigFolder | Where-Object {!$_.PsIsContainer} |
ForEach-Object {
if($_.BaseName -match $Regex){
# If first part of the file name is empty,
# move it to the 'Unknown' folder
if(!$Matches[1]){
$ChildPath = $UnknownFolder
} else {
$ChildPath = $Matches[1]
}
# Generate new folder name
$FolderName = Join-Path -Path $NewFolder -ChildPath $ChildPath
# Create folder if not exists
if(!(Test-Path -LiteralPath $FolderName -PathType Container)){
$null = New-Item -Path $FolderName -ItemType Directory
}
# Basic logging
Write-Host "$($_.FullName) -> $FolderName"
# Move file
Move-Item -LiteralPath $_.FullName -Destination $FolderName
}
}
Salvar como MoveFiles.ps1
e executar no console do PowerShell da seguinte forma: .\MoveFiles.ps1