Windows: how can I move a file with a long path to the trash?

I use Python, but I think the same problem exists in C #.

I would like to be able to support extended paths (paths with len> 260, which are represented as //? / C: / blah / blah). It seems like the standard way to move files to the trash is SHFileOperationW or SHFileOperation.

In python, the useful xplatform library, move2trash, uses SHFileOperationW. Several articles in C # say to use the same thing.

The problem with SHFileOperationW is that it does not support extended paths. This is a common limitation of SH tools.

Does anyone have any tricks for working with the cart and advanced paths?

Links Links: Version C # , the Python version

+5
source share
2 answers

A quick search for "PathTooLongException" raises quite a bit of discussion about stack overflows if you want to take a look at some C # solutions. You may be able to get the "short name" and use it to move it. Alternatively, you can look and see how they processed it in this C # library with a workaround at http://bcl.codeplex.com/wikipage?title=Long%20Path

0
source

No. Cannot put file in trash that is longer than 259 characters.

0
source

All Articles