?
Solved

Rename long file names powershell script

Posted on 2014-10-27
2
Medium Priority
?
2,331 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

777 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