user3088731
user3088731

Reputation: 67

Shell Scripting Error

$path='C:\Desktop\f'
$r=Get-ChildItem -Path $path -Filter *.deb

for($i=0; $i -lt $r.Count; $i++){
do { 
  get-content $r[$i] 

this is a pseudo code of the program I am trying to write the path I am trying to fetch is on desktop in a folder called f

but $r[$i] is different for example

the error as is

get-content : Cannot find path 'C:\Desktop\6747.deb' because it does not exist.
At C:\Desktop\deb.ps1:7 char:3
+   get-content $r[$i]| % {

even though my path is in desktop folder f why is it just going till dekstop and not any further

the deb.ps1 file is present on the desktop

Upvotes: 1

Views: 51

Answers (2)

Mike Shepard
Mike Shepard

Reputation: 18176

Even easier is to use a pipe:

$r[i] | get-content

or to simplify the whole script:

$path='C:\Desktop\f'
Get-ChildItem -Path $path -Filter *.deb | get-content

Upvotes: 0

Tim Ferrill
Tim Ferrill

Reputation: 1674

Your problem is that $r is a list of objects, not file names. Try this instead:

Get-Content $r[$i].FullName

Upvotes: 1

Related Questions