Solved

Rename long file names powershell script

Posted on 2014-10-27
2
1,344 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

Shouldn't all users have the same email signature?

You wouldn't let your users design their own business cards, would you? So, why do you let them design their own email signatures? Think of the damage they could be doing to your brand reputation! Choose the easy way to manage set up and add email signatures for all users.

Join & Write a Comment

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

706 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

18 Experts available now in Live!

Get 1:1 Help Now