我無法刪除文件,因為它的路徑太長

我無法刪除文件,因為它的路徑太長

我有一個包含要刪除的檔案的目錄。但是,檔名太長:

> Remove-Item -Recurse target
Remove-Item : 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.

我也無法在 Windows 資源管理器中使用shift+刪除它:delete

螢幕截圖

我也無法移動該文件,因為它的名稱太長。有什麼辦法可以刪除該檔案嗎?我使用 Windows 8.1。如果您能解釋這樣的檔案如何最終出現在我的磁碟機上,以及為什麼 Explorer 和 PowerShell 無法刪除它,那就加分了。

答案1

您應該能夠使用DeleteFile()和路徑使用長路徑符號,如\\?\C:\path\to\your\file.class.

從連結的 MSDN 頁面:

在此函數的 ANSI 版本中,名稱僅限於MAX_PATH字元。若要將此限制擴展到 32,767 個寬字符,請呼叫該函數的 Unicode 版本並新增"\\?\"到路徑前面。有關更多信息,請參閱命名文件

相關內容