none
icacls /reset fails on files that exceed MAXPATH limit RRS feed

  • Question

  • I'm running the following command on a large dataset (This is to reset permissions on all files below the specified path)

    icacls "M:\Archive\*" /c /t /reset

    (/c and /t = process all subfiles and folders and continue on all errors)

    When i run this command, i get a lots of errors where the path obviously exceeds 260 chars (ie  MAXPATH length), and so the script doesn't reset permissions on these files.

    What is the best way to resolve this?


    • Edited by markey165 Friday, May 20, 2016 12:44 PM
    Friday, May 20, 2016 12:43 PM

Answers

  • Hi Mary,

    Whilst you may not know of any solutions, this doesn't mean they do not exist.

    In this case, researching the problem further, I have now found 2 working solutions, and have detailed this below for anyone else that comes across this thread.

    Firstly, reading the MSDN documentation on max_path more carefully it says:

    "The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters........To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".

    So prefixing my path with the string "\\?\" as below, allows icacls to successfully address longer file paths.

    icacls "\\?\M:\Archive\*" /c /t /reset

    When my script runs using this prefix, it now runs correctly, and successfully processes all files without error....SUCCESS!!! NB this also works with UNC paths.

    The second method was to use setacl.exe written by Helge Klein (MVP).

    https://helgeklein.com/setacl/feature-set/

    One of its features is specifically listed as:

    • works with paths longer than 260 characters (MAX_PATH)

    The above tool is quite powerful and was slightly more complex than what was needed, so i used the first method outlined above.

    Hopefully this helps someone else.


    • Marked as answer by markey165 Thursday, May 26, 2016 9:55 AM
    • Edited by markey165 Thursday, May 26, 2016 6:23 PM
    Thursday, May 26, 2016 9:54 AM

All replies

  • Hi markey165,

    Thanks for your post.

    In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters.  In this case, you may try to work around this problem by passing Win32 a path that is MAX_PATH or less.

    I'm afraid that you could only rename the problematic folder to reduce the number of characters to less than  MAX_PATH

    For more information, please check the following KB article.

    Path too long error message when exceeding MAX_PATH

    http://support.microsoft.com/kb/177665

    Best Regards,

    Mary


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, May 23, 2016 2:21 AM
    Moderator
  • Hi Mary,

    Just to clarify, I know what MAX_PATH is, hence why i referred to it in the post. As mentioned, the dataset here is large (over 2 million files) so renaming is not a viable option. This requires automation hence why i attempted to use icacls. 

    What i need is a method that can do this in an automated fashion, that isn't affected by the 260 char MAX_PATH limit, in the same way that Robocopy handles file paths with the same long path issue.

    I was just wondering how other people manage this, as renaming them is fairly unlikely to be the ONLY solution to this problem.

    Thanks

    Mark


    • Edited by markey165 Monday, May 23, 2016 8:22 AM
    Monday, May 23, 2016 8:21 AM
  • Hi Mark,

    Thanks for your reply.

    As far as I know since windows limitation, there is few direct solution to this problem.

    https://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath

    Shorten file names could be the effective way to resolve the issue.

    Here is the thread discussed before, you might take a look.

    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/ce13105a-3088-4903-8334-6f9782d98ae1/getchilditem-the-specified-path-file-name-or-both-are-too-long-the-fully-qualified-file-name?forum=ITCG

    Best Regards,

    Mary


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, May 23, 2016 9:42 AM
    Moderator
  • Hi Mary,

    Whilst you may not know of any solutions, this doesn't mean they do not exist.

    In this case, researching the problem further, I have now found 2 working solutions, and have detailed this below for anyone else that comes across this thread.

    Firstly, reading the MSDN documentation on max_path more carefully it says:

    "The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters........To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".

    So prefixing my path with the string "\\?\" as below, allows icacls to successfully address longer file paths.

    icacls "\\?\M:\Archive\*" /c /t /reset

    When my script runs using this prefix, it now runs correctly, and successfully processes all files without error....SUCCESS!!! NB this also works with UNC paths.

    The second method was to use setacl.exe written by Helge Klein (MVP).

    https://helgeklein.com/setacl/feature-set/

    One of its features is specifically listed as:

    • works with paths longer than 260 characters (MAX_PATH)

    The above tool is quite powerful and was slightly more complex than what was needed, so i used the first method outlined above.

    Hopefully this helps someone else.


    • Marked as answer by markey165 Thursday, May 26, 2016 9:55 AM
    • Edited by markey165 Thursday, May 26, 2016 6:23 PM
    Thursday, May 26, 2016 9:54 AM
  • I suggest u to use Long Path Tool Program it will work for sure.
    Saturday, June 4, 2016 1:55 PM
  • Thankyou, i have just downloaded the software, but i can see no option in the software or documentation for managing file permissions, eg the equivalent of an icacls /reset?
    Tuesday, June 7, 2016 2:59 PM
  • Hi Mary,

    Whilst you may not know of any solutions, this doesn't mean they do not exist.

    In this case, researching the problem further, I have now found 2 working solutions, and have detailed this below for anyone else that comes across this thread.

    Firstly, reading the MSDN documentation on max_path more carefully it says:

    "The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters........To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".

    So prefixing my path with the string "\\?\" as below, allows icacls to successfully address longer file paths.

    icacls "\\?\M:\Archive\*" /c /t /reset

    When my script runs using this prefix, it now runs correctly, and successfully processes all files without error....SUCCESS!!! NB this also works with UNC paths.

    The second method was to use setacl.exe written by Helge Klein (MVP).

    https://helgeklein.com/setacl/feature-set/

    One of its features is specifically listed as:

    • works with paths longer than 260 characters (MAX_PATH)

    The above tool is quite powerful and was slightly more complex than what was needed, so i used the first method outlined above.

    Hopefully this helps someone else.


    Hi markey,

    Thanks so much for sharing the solution. I'm also learn a lot from that.

    Best Regards,

    Mary


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, June 8, 2016 12:58 AM
    Moderator
  • Thanks @markey165.  Another working solution is to use a virtual drive anchored further down the tree.  e.g. . If you wanted to run `icacls "C:\data\one\two\three\athousand\subdirectories\*" /c /T /reset`you would first `subst k: C:\data\one\two\three\athousand\subdirectories\` followed by `icacls k:\* /reset /c /t`

    Note, with sysinternals' AccessEnum, paths longer than MAX_PATH have Read and Write permissions displayed as ???.  Your \\?\D:\ syntax gets around this.  I still have a few "The system cannot find the path specified" but that may be for legitimate issues with the file system (or possibly just failing to follow symlinks/junctions).

    • Edited by mpags Thursday, February 16, 2017 8:51 PM added AccessEnum info
    Thursday, February 16, 2017 8:44 PM
  • the \\?\ prefix seems to fix it for me, thanks.

    However, I could not get it to work with an UNC path so I mapped the unc path to al local drive letter first.

    Thursday, August 24, 2017 8:19 AM