2014-06-23 3 views
0

이것이 가능한지 궁금해서 "스플릿 경로"를 잘못 사용하려고했는데 파일 이름이 불분명 해졌습니다. 미리 감사드립니다.스플릿 파일 전체 이름 경로

실제 출력 :

\\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 

원하는 출력 :

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 Green "$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 Red "FAIL" 
} 

답변

1

이 시도 할 수 있습니까?

Name="Ficheros";Expression={$_.FullName -replace '.*?(\\Desktop.*)','$1'} 

편집 : 비 욕심 정규식에 대한 업데이트 나는 그냥 아주 비슷한 기록했다 @TheMadTechnician

+0

에 의해 제안. 그래도 탐욕스럽지 않은'. *? '를 원한다. 그렇지 않으면 Desktop이라는 이름의 하위 폴더가 있으면 올바르게 구문 분석하지 않을 것이다. – TheMadTechnician

+0

탐욕스럽지 않은 것이 항상 좋습니다! –

+0

@AdilHindistan flawlesly 일했습니다! – pedaleo

관련 문제