So try my script on a machine with PS 5.1.
Is there some functionality in PS 7.2 that you need?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The code lines and the error
cd C:\save\dell_inspiron_ubuntu\save\save_z570\more\dir123\soft\exo\sou_predare1\dir123GCP\ExoModulesExtensions\platform-stable-4.1.x\samples\wai-template\src\main\webapp\WEB-INF\conf\sample-portal\wcm\artifacts\nodetype-templates\siteBreadcrumbWebContent
$ErrorActionPreference = 'Continue'
$ErrorView = 'NormalView' #all error messages
(Get-Date -UFormat '%Y-%m-%d %H:%M:%S').toString() + '.' + ((Get-Date).millisecond)
Get-ChildItem -Force -recurse | Select-Object FullName, Name, BaseName, Extension, Length, Mode, Attributes,
{$_.CreationTimeUTC.Ticks}, {$_.CreationTimeUTC.TimeOfDay},
{$_.LastWriteTimeUTC.Ticks}, {$_.LastWriteTimeUTC.TimeOfDay},
CreationTimeUTC, LastWriteTimeUTC, CreationTime, LastWriteTime, LastAccessTime > 2056_power_shell.txt
(Get-Date -UFormat '%Y-%m-%d %H:%M:%S').toString() + '.' + ((Get-Date).millisecond)
2022-02-20 08:17:31.33
Get-ChildItem : The system cannot find the path specified.
At line:5 char:6
Name Value
PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.19042
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
(4) I added a letter "dell_inspiron_ubuntu --> dell_inspiron_ubuntu1" and it works OK
I deleted a letter I added a letter "dell_inspiron_ubuntu --> dell_inspiron_ubunt" and it works OK
The path length is 256 and who knows what code crash is inside the PowerShell while migrating from older versions (3.x) where it crashed at ALL long directories
By the way, you may have a default 3.x PowerShell version now - install the new one
So try my script on a machine with PS 5.1.
Is there some functionality in PS 7.2 that you need?
it appears only on some special cases, around the path length of 256. Most of the times works
Based on that statement, I wrote a script to test to see if PS had a problem with a specific file name length. I tested this on Win11 and PS5.1.
I discovered that Powershell_ISE does not like long file names. I had to run the script in Powershell.exe.
Since you have PS7.2 give this a try and see if it works. Note that I tweaked your folder name for my testing.
cls
$x = get-itemproperty HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -name LongPathsEnabled
if ($x.LongPathsEnabled -eq 1) {
"Long file names are enabled."
} else {
"Long file names are NOT enabled."
}
Remove-Item -Path 'C:\temp\dell_inspiron_ubuntu' -Recurse
$start = 'C:\temp\dell_inspiron_ubuntu\save\save_z570\more\dir123\soft\exo\sou_predare1\dir123GCP\ExoModulesExtensions\platform-stable-4.1.x\samples\wai-template\src\main\webapp\WEB-INF\conf\sample-portal\wcm\artifacts\nodetype-templates\siteBreadcrumbWeb'
"The starting length is {0}" -f $start.length
New-Item -Path $start -ItemType Directory | out-null
1..25 | foreach {
$Subfolder = "$start\$('x' * $_)"
New-Item -Path $Subfolder -ItemType Directory | out-null
$_ | out-file $Subfolder\X.txt # create a subfolder and put a file in there too.
}
Get-ChildItem $start -recurse -File | foreach {
"{0} - {1}" -f $_.fullname.length, $_.fullname.Substring(($_.fullname.Length -50),50)
}
"Now read content."
Get-ChildItem $start -recurse -File | foreach {
Get-content $_.fullname
}
The limitation isn't in PowerShell, it's in the operating system.
Enable long file name support: enable-long-file-name-support-windows-10
Instead of making that long directory name the working directory try doing it this way:
Get-ChildItem "\\?\C:\save\dell_inspiron_ubuntu\save\save_z570\more\dir123\soft\exo\sou_predare1\dir123GCP\ExoModulesExtensions\platform-stable-4.1.x\samples\wai-template\src\main\webapp\WEB-INF\conf\sample-portal\wcm\artifacts\nodetype-templates\siteBreadcrumbWebContent" -recurse
Unfortunately, MS code has a strange way to crush
I executed your code that created a lot of files and then this (one with 265 works one crashed (in fact the crash could be at the next file - who knows who is the next file))
PS C:\save>
$ErrorActionPreference = 'Continue'
$ErrorView = 'NormalView' #all error messages
(Get-Date -UFormat '%Y-%m-%d %H:%M:%S').toString() + '.' + ((Get-Date).millisecond)
Get-ChildItem -Force -recurse | foreach {
"{0} - {1}" -f $_.fullname.length, $_.fullname.Substring(
[math]::max($_.fullname.Length - 50, 0),
[math]::min($_.fullname.Length, 50))
}
(Get-Date -UFormat '%Y-%m-%d %H:%M:%S').toString() + '.' + ((Get-Date).millisecond)
The result has more than 1600 characters so I have to attach it here