Solved

Rename long file names powershell script

Posted on 2014-10-27
2
2,090 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 11

Accepted Solution

by:
Joe Klimis 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

687 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