Solved

Rename long file names powershell script

Posted on 2014-10-27
2
1,471 Views
Last Modified: 2014-11-24
Hi Guys,

I need to migrate a share to a different location, however quite a few of the files within the folder share is very long, therefore when i attempt to migrate i get the error:

“File name(s) would be too long for the destination folder. You can shorten the file or try a destination that has a shorter path."

is there a powershell script i can use to rename these long file names?

thank you in advance,
Kelly
0
Comment
Question by:Kay
2 Comments
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40406775
Here is a script to find all of the files that are longer than 260 characters so you can rename them yourself. It wouldn't be a good idea to automatically rename files, they may get lost.

Just replace C:\ with the path you want to check.

Get-ChildItem "C:\" -recurse | Where {$_.GetType().Name -match "File" -and $_.FullName.length -ge 260} | Foreach {$_.FullName}

Open in new window


If you want it to save to file instead of listing on screen just add
 | Out-File C:\filelist.txt

Open in new window

0
 
LVL 10

Accepted Solution

by:
JoeKlimis earned 500 total points
ID: 40435091
Which version of windows are you using ?  
I would recommend using robocopy utility , it is much faster than Powershell   and restartable if interrupted

Robocopy comes with windows and to get help on the syntax open a   robocopy /?

Robocopy "C:\OriginalShare" "\\Machine2\newshare" /MIR

Open in new window

2

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now