We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x
Private

Powershell & Windows Batch: scanning folders with a path too long

Luis Diaz
Luis Diaz asked
on
High Priority
40 Views
Last Modified: 2020-05-22
Hello experts,

Some times I use robocopy command but I noticed when I remove folder I have folder cannot be found on your system due
the maximum length for a path (file name and its directory route, ie: MAX_PATH that has been defined by 260 characters).

I am looking for a script/command that allows me to scan a folder and know if its subfolders are above the limit.
Powershell or Windows batch are more than welcome.

If you have question, questions, please contact me.
Comment
Watch Question

Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Luis DiazIT consultant

Author

Commented:
Thank you very much Bill!

All approaches are valid.

I am going to take TreeSize search option:

20200522_130958.png
If I use another computer I can take Powershell/Windows Batch + Excel approach.
Two additional questions:
1.Powershell approach: how can I extract the result in a csv file?
2.Rule of 255 char is applied for NTFS disks? What about exFAT?

Regards,
Luis.
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
For the Powershell, simplest thing is to just pipe the output to a file:

gci C:\ -r | ? { $_.FullName.length -gt 255 } | select -expandproperty fullname > out.txt


ยปbp
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Luis DiazIT consultant

Author

Commented:
Thank you Bill for this useful advice!
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Welcome.

ยปbp
Joe WinogradDeveloper
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2018

Commented:
Hi Luis,
I see that you have an excellent solution from Bill, but just wanted you to know that Windows 10 allows you to enable long paths (it is disabled by default). There are two ways to do it:

(1) Change the registry manually:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem

Set LongPathsEnabled to 1

(2) Change it by running gpedit.msc and doing the following steps:

Local Computer Policy
Computer Configuration
Administrative Templates
System
Filesystem
Enable NTFS long paths (or it may say Enable Win32 long paths)

The second method avoids having to change the registry manually (which makes a lot of people uncomfortable), but it results in the same registry change described in the first method.

Regards, Joe
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
At some point that Policy setting moved up a level, here's where it is on my Windows 10 machine (patched up to current version).

sshot-254.png

ยปbp
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
And, I'm pretty sure that this doesn't solve all the worlds problems.  As I recall some applications, including Windows Explorer, will still trip over file paths that are too long...  ๐Ÿ˜

Joe WinogradDeveloper
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2018

Commented:
Hi Bill,
That's where it is in gpedit on my V1909. I think your screenshot and my list of steps are equivalent, but your screenshot is very nice...thanks for posting. To return the favor, here's the registry screenshot from V2004:

registry w10 v2004 LongPathsEnabled
Regards, Joe
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
You're right Joe, your post was accurate, I somehow thought you had the "NTFS" node before the actual value, must have seen an extra "NTFS" in there, my eyes aren't what they used to be.  ๐Ÿ˜‰

At least we have the two names it was called now too.
Joe WinogradDeveloper
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2018

Commented:
> As I recall some applications, including Windows Explorer, will still trip over file paths that are too long..

I don't know. I haven't bumped into that problem, but I don't often have a file path/name more that 260, and I never use Windows/File Explorer (my file manager is Total Commander).

> my eyes aren't what they used to be

I hear ya. :)

Regards, Joe
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
@Joe,

ZtreeWin here ๐Ÿ˜
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.