powershell - Remove parent path -
the following script lists file in directory , return name , path in console.
the result like:
c:\projects\company\trunk\www\client\project\customer\start.js
i need instead removing initial part , having result like
project\customer\start.js
i not able set right regular expression in replace. please point me out in right direction?
get-childitem -path c:\projects\company\trunk\www\client\project -filter *.js -recurse -file | sort-object length -descending | foreach-object { $_ = $_ -replace '\\c:\projects\company\trunk\www\client\project', '' "'" + $_.fullname + "'," }
$_
fileinfo
object, not string, path doesn't start backslash, , backslashes in search string must escaped if want use -replace
operator.
try this:
$basedir = 'c:\ppp\nnn\trunk\www\client' $pattern = [regex]::escape("^$basedir\") get-childitem -path "$basedir\nnn" -filter *.js -recurse -file | sort-object length -descending | foreach-object { $_.fullname -replace $pattern }
Comments
Post a Comment