powershell - Split File Fullname path -
powershell - Split File Fullname path -
i wondering if possible, tried utilize "split-path" wrongly , filename dissappears. in advance.
actual output:
\\myhostname\c$\users\myuser\desktop -- 9,05 mb ficheros megas -------- ----- \\myhostname\c$\users\myuser\desktop\something.exe 5,00 \\myhostname\c$\users\myuser\desktop\photo.jpg 2,00
desired output:
ficheros megas -------- ------ \desktop\something.exe 5,00 \desktop\photo.jpg 2,00
code:
param([string]$pc,[string]$user) $w7="\\$pc\c$\users\$user\desktop" if(test-path $w7){ #desktop: $colitems = (get-childitem $w7 | measure-object -erroraction "silentlycontinue" -property length -sum) $msg = "$w7 -- " + "{0:n2}" -f ($colitems.sum / 1mb) + " mb" write-host -foregroundcolor greenish "$msg" #files: get-childitem -recurse -force -include *.* -exclude *.ini, *.lnk $w7 -erroraction "silentlycontinue" | ls | select-object @{name="ficheros";expression={$_.fullname}}, @{name="megas";expression={$_.length / 1mb}} } else{ write-host -backgroundcolor white -foregroundcolor reddish "fail" }
can seek this?
name="ficheros";expression={$_.fullname -replace '.*?(\\desktop.*)','$1'}
edit: updating non-greedy regex suggested @themadtechnician
powershell
Comments
Post a Comment