Search This Blog

Use Get-FolderItem.ps1 to Fix PathTooLongException

When using Get-ChildItem to list all files in a folder and its subfolders, it returns the “PathTooLongException” error. This happens when the file path is more than 260 characters.

There are several ways to work around this issue. See this Technet Wiki.

Personally, I found the Get-FolderItem.ps1 script is the easiest one.

  1. Download the script from Microsoft Script Center Repository
  2. Right-click on the script and select Properties, then click Unblock
  3. Launch a PowerShell session
  4. Load the Get-FolderItem function into the session by entering “. <path>\Get-FolderItem.ps1”. (make sure there is a space between the “.” and the script)
  5. Enter “Get-FolderItem –Path <path>” to list all files in the folder and its subfolders
  6. Another use case “Get-FolderItem –Path <path> | Where {$_.LastWriteTime –gt “MM/DD/YYYY” } | Select FullName | Ft –autosize | Out-File c:\temp\modified.file.log.txt –width 4096

For more information about the Get-FolderItem.ps1 script, see this.

2 comments:

  1. Hi Eddie! I love this script except for a couple little issues I cannot figure out how to account for. First off, I noticed that when you are in a folder that has a specific problematic file in it, for example, the ones I'm having issues with this moment contain a character, that even when browsing in the cmd prompt and doing a dir of the directory, the file name it lists cannot be accessed as it's displayed.

    The dash character is where this issue seems to revolve around. The file name has dash in it, that is not the standard dash character "-". The Dash that I see and the script cannot capture correctly is called a en-dash and uses the AltCode 0150, "–" As you can see in this post, the two dashes are not identical. However from in the Windows Command prompt, or PowerShell, that dash seems to be converted into a normal dash.

    Do you have any idea how I can try to account for this or work around it? I've noticed a few other characters that have problems but have not identified them yet.

    ReplyDelete
    Replies
    1. Hi Glenn, this script is based on robocopy to work around the long file path (more than 260 characters). Try using robocopy to copy the file you are talking. If it fails, this script won't work.

      If you have identified the "trouble" file, you try deleting it by following this KB (https://support.microsoft.com/en-us/kb/131702). Hope this help.

      Delete

Use WinSCP to Transfer Files in vCSA 6.7

This is a quick update on my previous post “ Use WinSCP to Transfer Files in vCSA 6.5 ”. When I try the same SFTP server setting in vCSA 6.7...