Delete directories with long paths

30 Mar 2016

powershell windows

If you ever get this error The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. this is what you can do to solve it.

Update:
new versions of Windows 10 doesn't have the path length limit

Open powershell console, create empty directory and use robocopy to mirror it content to directory you want to delete. Robocopy will delete all files from desired directory and then you will be able to delete both directories.

md <new_empty_dir>
robocopy <new_empty_dir> <dir_you_want_to_delete> /MIR
rm <new_empty_dir> <dir_you_want_to_delete>

Command reference: md robocopy rm

You can also invoke cmd command from powershell console (some claim it not always work)

Cmd /C "rmdir /S /Q <dir_you_want_to_delete>"

Original source: StackOverflow


Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.