lizaoreo
-
Total Posts
:
13
- Scores: 0
-
Reward points
:
0
- Joined: 1/31/2008
- Location: Calhoun, GA
-
Status: offline
|
Filter Out Filename from Full Path String
Wednesday, November 24, 2010 3:18 AM
( permalink)
I'm working on filter job results for some jobs that run robocopy to pull out the currently copying file. Currently, I've got to the point that I can list the most recent file copying as shown in the sample script below. Unfortunately, I can't for the life of me figure out how to cut out the data I want from that point. My results are coming back like this: C:\WINDOWS\source\I386\SM59W.DL_ C:\WINDOWS\source\I386\SM81W.DL_ C:\WINDOWS\source\I386\SM87W.DL_ C:\WINDOWS\source\I386\SM89W.DL_ C:\WINDOWS\source\I386\SM8AW.DL_ I'm wanting something more like this: SM59W.DL_ SM81W.DL_ SM87W.DL_ SM89W.DL_ SM8AW.DL_ $job = {robocopy C:\ C:\test /e /L /nS /nc /ndl}
$jobs = start-job $job
start-sleep -seconds 3 function Get-LatestResult ($results)
{
$lresults = $results.length - 1
$output = $results[$lresults]
return $output
} while (Get-Job -State "Running") {
$results = (Receive-Job -job $jobs)
Get-LatestResult $results
start-sleep -seconds 1
} I know this one has to be simple, probaby using Trim or something, I figure I can use the last "\" as a filter, but I can't seem to single it out and cut out the rest.
|
|
|
|
lizaoreo
-
Total Posts
:
13
- Scores: 0
-
Reward points
:
0
- Joined: 1/31/2008
- Location: Calhoun, GA
-
Status: offline
|
Re:Filter Out Filename from Full Path String
Monday, November 29, 2010 3:52 AM
( permalink)
Think I've solved my problem using the string split method. function Get-LatestResult ($results)
{
$lresults = $results.length - 1
$path = $results[$lresults]
$path = $path.split("\")
$lpath = $path.length - 1
$output = $path[$lpath]
return $output
}
|
|
|
|
TomRiddle
-
Total Posts
:
620
- Scores: 12
-
Reward points
:
0
- Joined: 2/7/2008
- Location: Australia
-
Status: offline
|
Re:Filter Out Filename from Full Path String
Tuesday, November 30, 2010 3:54 PM
( permalink)
This works for me :) function Get-LatestResult ($results) { split-path $results -leaf }
-join([int[]][char[]]'Ut|jwXmjqq%Wzqjx'|%{[char]($_-5)})
|
|
|
|
anytua34i
-
Total Posts
:
9
- Scores: 0
-
Reward points
:
0
- Joined: 1/24/2011
-
Status: offline
|
Re:Filter Out Filename from Full Path String
Monday, January 24, 2011 7:13 PM
( permalink)
|
|
|
|