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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -