Program to custom truncate filenames?

Soldato
Joined
26 May 2009
Posts
22,152
Short story, bought a new Synology NAS, it has hardware support for encryption, this requires a maximum file or folder name of 143 characters including file extensions (total path length is irrelevant). Some of the folders I want to copy over to the new encrypted share have files in them with names > 143 characters, this is a problem (shock).

So yeah, I'm looking for a program I can basically point at a directory and have it shorten the names of all the files/folders in that folder and sub folders to a custom limit.

Any ideas? :)
 
PowerShell?

Rename files.

Code:
$maxlength = 10
$directory = "C:\Test\1"
Get-ChildItem -Path $directory -Recurse -File | Where {$_.Name.Length -gt $maxlength} | ForEach {Rename-Item -Path $_.FullName -NewName "$($_.Name.Substring(0, $maxlength - $_.Extension.Length))$($_.Extension)"}

Rename directories.

Code:
$maxlength = 10
$directory = "C:\Test\1"
Get-ChildItem -Path $directory -Recurse -Directory| Where {$_.Name.Length -gt $maxlength} | ForEach {Rename-Item -Path $_.FullName -NewName $_.Name.Substring(0, $maxlength)}
 
Back
Top Bottom